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(dfs)

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

  2. DFS+打表

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

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

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

  4. POJ-3134-Power Calculus(迭代加深DFS)

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

  5. 奇偶交错排列(DFS)

    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.5_1789】算24(dfs)

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

  8. DFS模板

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

  9. [hdu4582]DFS spanning tree

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

随机推荐

  1. nsDATA 转结构体

    很多时候需要将c,c++形式的struct转换为  NSData来处理.但是怎么转换呢? 假设有这么一个结构体: struct   MYINFO { int   a; long  b; char  c ...

  2. LR之错误处理

    1.脚本的健壮性 2.VuGen的处理机制 3.lr_continue_on_error函数 4.示例代码

  3. JS判断是不是本页面并且,给标签添加属性和属性值

    大多是在导航栏中用到的,在导航栏中在主页和在其他的网页点击导航栏中的主页是不同的,主要就是判断这个. 我是在ascs页面中写的. 下面先看标签: <a href="http://www ...

  4. 【LeetCode】231 - Power of Two

    Given an integer, write a function to determine if it is a power of two. Solution:一个整数如果是2的整数次方,那么它的 ...

  5. Mapreduce执行过程分析(基于Hadoop2.4)——(三)

    4.4 Reduce类 4.4.1 Reduce介绍 整完了Map,接下来就是Reduce了.YarnChild.main()—>ReduceTask.run().ReduceTask.run方 ...

  6. 一个相当好的状态机(DFA, 确定有限状态机)的编码实现,相当简洁漂亮

    从jsoup而来,文章见: https://github.com/code4craft/jsoup-learning/blob/master/blogs/jsoup4.md 状态机 Jsoup的词法分 ...

  7. 实体框架 (EF) 入门 => 五、连接和模型

    public class BloggingContext : DbContext  {  public BloggingContext()          : base("name=Blo ...

  8. 用完成例程(Completion Routine)实现的重叠I/O模型

    /// 用完成例程(Completion Routine)实现的重叠I/O模型 /// 异步IO模型 /// 用完成例程来实现重叠I/O比用事件通知简单得多.在这个模型中,主线程只用不停的接受连接 / ...

  9. chrome emulator use-agent 设置 chrom模拟手机客户端

    谷歌升级以后,发现找不到use-agent设置了 在Element 下点击ESC 出现console,再点击Emulation就出现了

  10. Labeled ContentControl & LabeledControl【项目】

    LabeledTextBoxControl: C#定义 using System; using System.Collections.Generic; using System.Linq; using ...