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. memcache、memcached、groupcache的区别

    对PHP语言来说,PHP使用memcache有两个模块,分别叫memcache和memcached,他们的区别看下表: 参考:http://hi.baidu.com/tony_wd/item/605e ...

  2. 编码的UI测试项目——Visual Studio 2013

    今天实现了一次编码的UI测试项目,以下是我进行测试的过程: 1.新建测试项目 在visual studio中(我用的版本是2013 update2)点击文件->新建->项目,选择“编码的U ...

  3. javascript面向对象实例

    非私有属性 function Student(name, gender, age, grade, teacher){ this.name = name; this.gender = gender; t ...

  4. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  5. 前端架构:Angular与requirejs集成实践

    这几天angular与requirejs.browserify的集成弄的博主头好晕,今天终于成功集成了requirejs,现写些心得体会在这里. 核心思想:angular加载时有一定的顺序,必须依次加 ...

  6. 自己使用python webob,paste.deploy,wsgi总结

    paste.deploy就是一个可以配置wsgi_app的工具,可以让服务器运行时,按照配置文件执行一系列的程序.需要使用.ini配置文件. (1)这里补充一下当时没看到的配置文件 1.[app:ma ...

  7. 数往知来 SQL SERVER 基本语法<七>

    sqlserver学习_01 启动数据库 开始->cmd->进入控制台    sqlcmd->-S .\sqlexpress    1> 如果出现表示数据库"sqle ...

  8. Python 学习笔记(五)杂项

    1. Assert assert len(unique_characters) <= 10, 'Too many letters' #…等价于: if len(unique_characters ...

  9. QS之warning message

    Multiple message categories are specified as a comma separated list.

  10. [转] Python自动单元测试框架

    一.软件测试 大型软件系统的开发是一个很复杂的过程,其中因为人的因素而所产生的错误非常多,因此软件在开发过程必须要有相应的质量保证活动,而软件测试则是保证质量的关键措施.正像软件熵(software ...