pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25)
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).
Assume that the lake is a 100 by 100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether or not he can escape.
Input Specification:
Each input file contains one test case. Each case starts with a line containing two positive integers N (<=100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x, y) location of a crocodile. Note that no two crocodiles are staying at the same position.
Output Specification:
For each test case, print in a line "Yes" if James can escape, or "No" if not.
Sample Input 1:
14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12
Sample Output 1:
Yes
Sample Input 2:
4 13
-12 12
12 12
-12 -12
12 -12
Sample Output 2:
No
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<string>
using namespace std;
struct point{
int x,y;
double dis;
bool vis;
point(){
vis=false;
}
};
double getdis(int x1,int y1,int x2,int y2){
int dx=x1-x2;
int dy=y1-y2;
return sqrt(dx*dx+dy*dy);
}
int abs(int a){
if(a<){
a=-a;
}
return a;
}
point cro[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,J;
int i;
queue<int> q;
scanf("%d %d",&n,&J);
point *cro=new point[n];
for(i=;i<n;i++){
scanf("%d %d",&cro[i].x,&cro[i].y);
cro[i].dis=getdis(,,cro[i].x,cro[i].y);
}
if(7.5+J>=){
printf("Yes\n");
return ;
}
for(i=;i<n;i++){
if(cro[i].dis<=7.5){
cro[i].vis=true;//无效点
}
else if(cro[i].dis<=7.5+J){//在弹跳范围内,收集
q.push(i);
cro[i].vis=true;
}
}
int curnum,x,y;
while(!q.empty()){
curnum=q.front();
q.pop();
x=cro[curnum].x;
y=cro[curnum].y;
if(abs(x)+J>=||abs(y)+J>=){//可以到达岸边
printf("Yes\n");
return ;
}
for(i=;i<n;i++){
if(!cro[i].vis){
cro[i].dis=getdis(x,y,cro[i].x,cro[i].y);
if(cro[i].dis<=J){
q.push(i);
cro[i].vis=true;
}
}
}
}
printf("No\n");
return ;
}
pat05-图2. Saving James Bond - Easy Version (25)的更多相关文章
- PTA 06-图2 Saving James Bond - Easy Version (25分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- 06-图2 Saving James Bond - Easy Version (25 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- 05-图2. Saving James Bond - Easy Version (25)
1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...
- PAT Saving James Bond - Easy Version
Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...
- 06-图2 Saving James Bond - Easy Version
题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625 This time let us consider the situation in ...
- 06-图2 Saving James Bond - Easy Version (25 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- 06-图2 Saving James Bond - Easy Version (25 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
随机推荐
- C# 链表 --增 -删-反转-删除最小值
1. Node.cs namespace 链表 { public class Node<T> { public T Data; //这个就是地址 public Node<T> ...
- (Delphi)第一个Windows 32 API的窗口程序
program Project1; uses Winapi.Windows, Winapi.messages; {$R *.res} const className = 'MyDelphiWindow ...
- Vim编辑器的学习
在老师的带领下,最近也算是涨了见识.自己安装并尝试着体验了Vim的一些基本功能,可能是作为初学者,总感觉其指令太过复杂,就文本编辑而言,给我的最大感受就是神而乎之,一头雾水.目前我对这款编译器的掌握水 ...
- 微信小程序小结(5) -- 常用语法
在 pages 字段的第一个页面就是这个小程序的首页(打开小程序看到的第一个页面). Page生命周期 属性 类型 描述 onLoad Function 生命周期函数--监听页面加载.一个页面只会调用 ...
- Flask 新闻网站
welcome to visit http://47.94.194.236 最近在搭建django,可能内容有问题,如访问异常,请给我留言! 项目源码托管于gihub 一.项目基本流程: 1.搭 ...
- SURF特征识别
如果对Surf的探究或者使用到此为止,我觉得只是用Surf这把牛刀吓唬了一个小鸡仔,万里长征才刚刚开始第一步,最少有三个问题需要得到解答: 1. 保存特征点信息的keyPoints向量内每个元素包含有 ...
- [Node.jS]shelljs
shelljs : https://www.npmjs.org/package/shelljs 要给可以替代Unix下shell脚本的库. require('shelljs/global'); if ...
- java Response 设置中文编码
response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setChara ...
- $.ajax 错误信息
$.extend({ getHtml:function(url,callback){ $.ajax({ dataType:"html", url:url, timeout:1500 ...
- 解决报错:import sun.misc.BASE64Decoder无法找到
解决报错:import sun.misc.BASE64Decoder无法找到 2017年09月29日 16:03:26 chaoyu168 阅读数:2116 标签: sun.misc.BASE64De ...