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

ZOJ 1860:Dog & Gopher的更多相关文章

  1. POJ 2610:Dog & Gopher

    Dog & Gopher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4142   Accepted: 1747 ...

  2. poj 2337 有向图输出欧拉路径

    Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10186   Accepted: 2650 Descrip ...

  3. nyoj 99 单词拼接

    点击打开链接 单词拼接 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 给你一些单词,请你判断能否把它们首尾串起来串成一串. 前一个单词的结尾应该与下一个单词的道字母相同 ...

  4. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. poj2337欧拉回路要求输出路径

                         Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8368   Ac ...

  6. 洛谷P1127-词链

    Problem 洛谷P1127-词链 Accept: 256    Submit: 1.3kTime Limit: 1000 mSec    Memory Limit : 128MB Problem ...

  7. POJ 2337 Catenyms (有向图欧拉路径,求字典序最小的解)

    Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8756   Accepted: 2306 Descript ...

  8. POJ 2337 Catenyms (欧拉回路)

    Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 2149 Descript ...

  9. poj 2337(单向欧拉路的判断以及输出)

    Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11648   Accepted: 3036 Descrip ...

随机推荐

  1. Vue指令3:v-for

    列表渲染 我们用 v-for 指令根据一组数组的选项列表进行渲染.v-for 指令需要使用item in items 形式的特殊语法,items 是源数据数组并且 item 是数组元素迭代的别名. & ...

  2. 11servlet接口

    11.servlet接口-2018/07/23 1.servlet 是一个接口,需要导包javax.servlet.Servlet; 第一种编写一个servlet程序的方法 写一个Java类,实现se ...

  3. JS中遍历EL表达式中后台传过来的Java集合

    前言:在我的项目里有这么一个情况,后台直接model.addAttribute()存储了一个对象,此对象内部有一个集合,前端JSP处理的方法正常情况下就是直接使用EL表达式即可.但是如果在JS中需要使 ...

  4. 一篇入门MongoDB

    目录 1.MongoDB 基本介绍 2.MongoDB 基本概念 3.数据库操作 4.集合操作 5.文档操作 6.查询条件 7.索引 1.MongoDB 基本介绍 (1)安装 MongoDB 简单来说 ...

  5. 可以通过dict[key]获得dict[value]

    dict={key:value,key2:value2} print (dict[key] )    得到的是 dict[value] # 软文预存接口,通过key来预览未保存的软文,联查商品.kol ...

  6. [bzoj2431][HAOI2009][逆序对数列] (dp计数)

    Description 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的 数列,可以很容易求出有多少个逆序对数.那么逆 ...

  7. ganglia371 on suse11sp3

    参考https://my.oschina.net/duangr/blog/181585 1.确认依赖包是否已安装 确认命令:rpm -qa  如下为适合suse11sp3的依赖包版本 apr: lib ...

  8. CSS3制作404立体字体

    CSS3制作404立体字体页面效果     鼠标移动上去,背景色变白.       动态效果:     .demo p:first-child span:hover { text-shadow:0px ...

  9. Leetcode 135.分糖果

    分发糖果 老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分. 你需要按照以下要求,帮助老师给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果. 相邻的孩 ...

  10. [luoguP2659] 美丽的序列(单调栈)

    传送门 单调栈大水题 l[i] 表示 i 能扩展到的左边 r[i] 表示 i 能扩展到的右边 ——代码 #include <cstdio> #include <iostream> ...