Dog & Gopher


Time Limit: 2 Seconds      Memory Limit: 65536 KB


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;
}

最新文章

  1. 解决ScrollView 嵌套 GridView 单行显示问题
  2. Android调用系统照相机
  3. Android Bitmap Drawable 常用摘要
  4. python 核心编程课后练习(chapter 2)
  5. 如何在ASP.NET中用C#将XML转换成JSON
  6. openid4java 使用记录[转载]
  7. JavaScript之菱形打印
  8. 让DJANGO里的get_success_url定义的reverse_lazy带参数跳转
  9. Find Security Bugs研究,邀请志同道合者一起参与
  10. 高级UNIX环境编程7 进程
  11. JavaScript 初识Promise 对象
  12. nyoj234 吃土豆 01背包
  13. 基于gin框架和jwt-go中间件实现小程序用户登陆和token验证
  14. [转]How to: Create a Report Server Database (Reporting Services Configuration)
  15. C# 百度TTS,文本转语音,RestAPI之Get请求
  16. mui做的苹果app生成ipa后放到自己的网站上让人下载安装
  17. ARC简介以及工程中ARC与非ARC的混合(转)
  18. 安装使用composer基本流程
  19. SQL Insert Case When Update
  20. dp练习(10)——拦截导弹

热门文章

  1. URL解析-URLComponents
  2. os下,vs code 自动编译ts
  3. js统计图表插件 Echarts
  4. react 返回上一页
  5. CUDA 动态编译(NVRTC)简记
  6. Makefile,Shell command,Shell Language 之间的联系
  7. UVA-12333 Revenge of Fibonacci(竖式加法模拟 &amp; 字典树)
  8. 创建和获取cookie
  9. POJ 3468 线段树区间修改查询(Java,c++实现)
  10. PAT 1125 Chain the Ropes