ZOJ 1860:Dog & Gopher
来源:互联网 发布:工作流管理系统源码 编辑:程序博客网 时间:2024/05/22 03:21
A large field has a dog and a gopher. The dog wants to eat the gopher, while the gopher wants to run to safety through one of several gopher holes dug in the surface of the field.
Neither the dog nor the gopher is a math major; however, neither is entirely stupid. The gopher decides on a particular gopher hole and heads for that hole in a straight line at a fixed speed. The dog, which is very good at reading body language, anticipates which hole the gopher has chosen, and heads at double the speed of the gopher to the hole, where it intends to gobble up the gopher. If the dog reaches the hole first, the gopher gets gobbled; otherwise, the gopher escapes.
You have been retained by the gopher to select a hole through which it can escape, if such a hole exists.
Input
The first line of input contains four floating point numbers: the (x,y) coordinates of the gopher followed by the (x,y) coordinates of the dog. Subsequent lines of input each contain two floating point numbers: the (x,y) coordinates of a gopher hole. All distances are in metres, to the nearest mm.
Input contains multiple test cases. Subsequent test cases are separated with a single blank line.
Output
Your output for each test case should consist of a single line. If the gopher can escape the line should read "The gopher can escape through the hole at (x,y)." identifying the appropriate hole to the nearest mm. Otherwise the output line should read "The gopher cannot escape." If the gopher may escape through more than one hole, choose the first one. There are not more than 1000 gopher holes and all coordinates are between -10000 and +10000.
Sample Input
1.000 1.000 2.000 2.000
1.500 1.500
2.000 2.000 1.000 1.000
1.500 1.500
2.500 2.500
Sample Output
The gopher cannot escape.
The gopher can escape through the hole at (2.500,2.500).
Source: University of Waterloo Local Contest 1999.09.25
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include<iostream> #include<cstdio> #include<sstream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; struct point { double x,y; int id; }; point hole,ans,dog,gopher; const double eps = 1e-6; void dist(point hole,double &todog,double &togop) { todog =sqrt((dog.x - hole.x)*(dog.x - hole.x)+(dog.y-hole.y)*(dog.y-hole.y)); togop = sqrt((gopher.x - hole.x)*(gopher.x - hole.x)+(gopher.y-hole.y)*(gopher.y-hole.y)); } char str[100]; int main() { while( ~scanf("%lf %lf %lf %lf\n",&gopher.x,&gopher.y,&dog.x,&dog.y)) { int flag = 1; double todog,togop; while(gets(str)) { if( strlen(str)==0)break; sscanf(str,"%lf%lf",&hole.x,&hole.y); dist(hole,todog,togop); if( flag && togop < todog *0.5) { printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",hole.x,hole.y); flag = 0; } } if(flag)puts("The gopher cannot escape."); } return 0; }
- ZOJ 1860:Dog & Gopher
- ZOJ 1860|| Dog & Gopher(空行区分case
- Dog and Gopher
- POJ 2610:Dog & Gopher
- [uva] 10310 Dog and Gopher
- UVA 10310 - Dog and Gopher
- uva 10310 - Dog and Gopher
- UVa 10310 - Dog and Gopher
- POJ 2610 Dog & Gopher G++
- UVa 10310 Dog and Gopher(long long)
- UVa 10310 Dog and Gopher(double)
- (挑战编程_13_1)Dog and Gopher
- POJ 2610 Dog & Gopher(水~)
- UVa Problem 10310 Dog and Gopher (狗拿地鼠)
- zoj 1882 || poj 2536 Gopher II
- zoj 3141 - nie's Dog Biscuits
- ZOJ 1882 Gopher II(二分图最大匹配)
- POJ 2536 Gopher II (ZOJ 2536) 二分图匹配
- HASH相关
- 我想静静2
- 修改git已经commit的邮箱和用户名
- 文件系统扫描的工具类
- MyEclipse2014 优化设置
- ZOJ 1860:Dog & Gopher
- ___19__C#手动编写Stack类,模拟栈的数据操作
- 如何防止android app被kill
- POJ 1065:Wooden Sticks
- Unicon字符串转成汉字String
- 【已解决】找不到android.support.v7.internal.app.WindowDecorActionbar
- callBackName cannot be found&fullPathForFilename: No file found at replay.png. 解决方案
- 优化Myeclipse启动速度
- 小C公众帮 获取微信公众号粉丝openid