cdoj 15 Kastenlauf dfs

时间:2023-01-14 19:25:49

Kastenlauf

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.uestc.edu.cn/#/problem/show/3

Description

Once every year, Jo and his friends want to visit the local fair in Erlangen, called Bergkirchweih. This year, they want to make a Kastenlauf (box run). They start at Jo's home, and have one box (Kasten) of beer (with twenty bottles). As they are very thirsty, they drink one bottle of beer every 50 metres.

As the way from Jo's home to the Bergkirchweih is pretty long, they need more beer than they have initially. Fortunately, there are stores selling beer on the way. When they visit a store, they can drop their empty bottles and buy new bottles, but their total number of full bottles will not be more than twenty (because they are too lazy to carry more than one full box).

You are given the coordinates of the stores, of Jo's home and of the location of the Bergkirchweih. Write a program to determine whether Jo and his friends can happily reach the Bergkirchweih, or whether they will run out of beer on the way.

Input

Input starts with one line containing the number of test cases t (t≤50).

Each test case starts with one line, containing the number n of stores selling beer (with 0≤n≤100). The next n+2 lines cointain (in this order) the location of Jo's home, of the stores, and of the Bergkirchweih. The location is given with two integer coordinates x and y, (both in meters, −32768≤x,y≤32767).

As Erlangen is a rectangularly laid out city, the distance between two locations is the difference of the first coordinate plus the difference of the second coordinate (also called Manhattan-Metric).

Output

For each test case print one line, containing either happy (if Jo and his friends can happily reach the Bergkirchweih), or sad (if they will run out of beer on the way).

Sample Input

2
2
0 0
1000 0
1000 1000
2000 1000
2
0 0
1000 0
2000 1000
2000 2000

Sample Output

happy
sad

HINT

题意

给你很多个点,要求每个点之间的距离小于等于1000就可以走过去,然后问你能否从起点走到终点

题解:

数据范围很小,直接爆搜

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200000
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//**************************************************************************************
struct node
{
int x,y;
};
node a[];
int n;
int flag[];
void dfs(int x)
{
if(flag[x])
return;
flag[x]=;
for(int i=;i<=n;i++)
{
if(i==x)
continue;
if(abs(a[i].x-a[x].x)+abs(a[x].y-a[i].y)<=)
dfs(i);
}
}
void solve()
{
memset(flag,,sizeof(flag));
memset(a,,sizeof(a));
scanf("%d",&n);
n+=;
for(int i=;i<=n;i++)
a[i].x=read(),a[i].y=read();
dfs();
if(flag[n])
cout<<"happy"<<endl;
else
cout<<"sad"<<endl;
}
int main()
{
//test;
int t=read();
for(int cas=;cas<=t;cas++)
{
solve();
}
}

cdoj 15 Kastenlauf dfs的更多相关文章

  1. How Many Equations Can You Find&lpar;dfs&rpar;

    How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  2. DFS&plus;打表

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  3. 【DFS】XIII Open Championship of Y&period;Kupala Grodno SU Grodno&comma; Saturday&comma; April 29&comma; 2017 Problem D&period; Divisibility Game

    题意:给你一个序列,长度不超过52,每个元素不超过13.让你重新对这个序列排序,sum(i)表示i的前缀和,使得排序过后,对每个i,都有sum(i)%i==0. 深搜,加两个优化:①倒着从后向前搜:② ...

  4. POJ-3134-Power Calculus&lpar;迭代加深DFS&rpar;

    Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multipli ...

  5. 奇偶交错排列&lpar;DFS&rpar;

    Description 一个1-n1−n的排列满足所有相邻数字奇偶性不同,那么称该排列为奇偶交错排列. 按字典序输出1-n1−n的所有奇偶交错排列. Input 输入一个整数n( 2 \le n \l ...

  6. SCUT - 31 - 清一色 - dfs

    https://scut.online/p/31 还是不知道为什么RE了.的确非常玄学. 重构之后就没问题了.果然写的越复杂,分的情况越乱就越容易找不到bug. #include<bits/st ...

  7. 【noi 2&period;5&lowbar;1789】算24(dfs)

    最开始我想的是全排列+枚举符号和括号的方法,但是我自己倒腾了很久还是打不对,只好向他人请教.正解很机智--直接随意将几个数"捆绑"在一起,值存在其中一个数上,其他数标记不可再选,直 ...

  8. DFS模板

    DFS模板 题型分类:我们可以将DFS题分为两大类: 1 . 地图型:这种题型将地图输入,要求完成一定的任务.因为地图的存在.使得题意清楚形象化,容易理清搜索思路.AOJ 869-迷宫(遍历地图,四向 ...

  9. &lbrack;hdu4582&rsqb;DFS spanning tree

    考虑每一条非树边都连接了祖先和儿子,类似于序列上的问题,从底往上算,当发现如果走到某个环的祖先,且这个环中还没有被选到,那么就将最浅的那条边贪心选择即可具体实现可以使用bitset维护当前子树的询问, ...

随机推荐

  1. ASP&period;NET MVC系列:Area

    1. Area简介 ASP.NET MVC Area机制构建项目,可以将相对独立的功能模块切割划分,降低项目的耦合度. 2. Area设置Routing 新建Admin Area后,自动创建Admin ...

  2. oracle一些基本语句

    --添加一个字段alter table 表名 add(列类型);--修改字段数据类型alter table 表名 modify(列类型);--删除一个字段alter table 表名 drop col ...

  3. ACM&sol;ICPC 之 最短路径-dijkstra范例&lpar;ZOJ2750-POJ1135&lpar;ZOJ1298&rpar;&rpar;

    最短路经典算法-dijkstra范例(两道),第一道是裸的dijkstra,第二道需要枚举所有边已找到可能的情况. ZOJ2750-Idiomatic Phrases Game 题意:见Code 题解 ...

  4. http&colon;&sol;&sol;blog&period;csdn&period;net&sol;jyw935478490&sol;article&sol;details&sol;51233931

    http://blog.csdn.net/jyw935478490/article/details/51233931

  5. Ubuntu安装图形桌面

    apt-get直接更新即可 apt-get install ubuntu-desktop

  6. php生成图片注释

    //生成验证码图片注释 <?php session_start(); $arr = array( 'a','b','c','d','e','f','g','h','i','j','k','l', ...

  7. PAT &lpar;Advanced Level&rpar; 1096&period; Consecutive Factors &lpar;20&rpar;

    如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #in ...

  8. Python爬去有道翻译

    注:传入的类型为POST类型,所以需要使用urllib.parse.urlencode(),将字典转换成URL可用参数: 使用json.loads(),将输出的json格式,转换为字典类型 impor ...

  9. 292&period; Nim Game&lpar;easy&rpar;

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  10. 逆向 AWS API 设计

    由于AWS并没有像Google一样公开出一份API Design Guide,所以只能根据 API 的模样去逆向工程最初的设计考量.既然上一篇介绍了很多 REST 的缺陷,那么这里也会介绍一下 AWS ...