ZOJ 1860:Dog & Gopher
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的更多相关文章
- POJ 2610:Dog & Gopher
Dog & Gopher Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4142 Accepted: 1747 ...
- poj 2337 有向图输出欧拉路径
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10186 Accepted: 2650 Descrip ...
- nyoj 99 单词拼接
点击打开链接 单词拼接 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 给你一些单词,请你判断能否把它们首尾串起来串成一串. 前一个单词的结尾应该与下一个单词的道字母相同 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- poj2337欧拉回路要求输出路径
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8368 Ac ...
- 洛谷P1127-词链
Problem 洛谷P1127-词链 Accept: 256 Submit: 1.3kTime Limit: 1000 mSec Memory Limit : 128MB Problem ...
- POJ 2337 Catenyms (有向图欧拉路径,求字典序最小的解)
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8756 Accepted: 2306 Descript ...
- POJ 2337 Catenyms (欧拉回路)
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8173 Accepted: 2149 Descript ...
- poj 2337(单向欧拉路的判断以及输出)
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11648 Accepted: 3036 Descrip ...
随机推荐
- vue基础---事件处理
(1)事件监听 v-on 指令监听 DOM 事件,并在触发时运行JS代码 <div class="event_area"> {{message}} <button ...
- 【loj6184】无心行挽(虚树+倍增)
题目链接:https://loj.ac/problem/6184 每次询问给一些关键点,询问树上每个点离最近的关键点的距离(以后称为f(u))最大值是多少. 询问数比较大,但 \sum{K} 和n是一 ...
- mybatis传参总结
注:文章引用部分 mybatis传递参数总结文章内容 一.单个参数 1.基本数据类型 (1)直接使用 List<ChargeRuleDO> tests(long id); <sele ...
- Anaconda安装xgboost的过程和踩过的坑
win10下安装xgb,安装的过程波折起伏,花了5个小时,给后来人做参考喽 第一次尝试 利用以下两个软件 Git for Windows.MINGW进行安装. 安装可以参考:(https://blog ...
- 洛谷——P2018 消息传递
P2018 消息传递 题目描述 巴蜀国的社会等级森严,除了国王之外,每个人均有且只有一个直接上级,当然国王没有上级.如果A是B的上级,B是C的上级,那么A就是C的上级.绝对不会出现这样的关系:A是B的 ...
- 39页第7题 计算2的i次方之和
/*计算2的i次方之和*/ #include<stdio.h> #include<math.h>/*调用math.h文件中的函数*/ int main(void) { int ...
- 每日命令:(5)rm
昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所 ...
- 访问请求参数request.getParameter()
访问请求参数request.getParameter() 制作人:全心全意 getParameter() 例: 传递参数页: <%@ page language="java" ...
- PHP 结合前端 ajax 爬取网站信息后, 向指定用户发送指定短信;
<?php /** * Description * @authors Your Name (you@example.org) * # 根据时时彩的最新一期的号码, 判断如果为首尾同号则发送短信 ...
- HDU - 6446 Tree and Permutation
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6446 本题是一个树上的问题——DFS. 一棵N个结点的树,其结点为1~N.树具有N-1条边,每一条边具有 ...