05-图2. Saving James Bond - Easy Version (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 05-图2. Saving James Bond - Easy Version (25)

    1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...

  4. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  5. 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 ...

  6. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. “网易大数据讲堂第一期:数说”直播活动资料:课程回放收看及PPT下载

    欢迎访问网易云社区,了解更多网易技术产品运营经验. "网易大数据讲堂第一期:数说"直播活动昨晚顺利举行.感谢各位"数"友的支持和参与. 本次活动PPT可点击这里 ...

  2. Linq to Objects for Java

    好几年不写博客了,人也慢慢变懒了.然而想写了却不知道写点啥,正好最近手头有点小项目就分享一下经历. 现在 java 的大环境下,基本都是围着 spring 转,加上一堆其他的库.有了架子就开始搞业务了 ...

  3. ubuntu - 14.04,常用PPA源(第三方提供的deb格式安装文件)!!

    说明: 1,下面所有PPA源的执行命令,均为在shell中执行的命令,需要依次执行! 2,下面所有测试方法,均为在shell中执行的命令!! PPA源: 一,Oracle JDK:Oracle公司提供 ...

  4. asp遍历前端的所有控件

    //遍历ID为Panel1的panel里的所有label控件 foreach (Control ctl in this.Panel1.Controls) { //判断类型为Label的 if (ctl ...

  5. [A/C 2007] 数据备份(网络流,堆)

    [A/C 2007] 数据备份(网络流,堆) 给你N各点的位置和K条链,需要用这些链把2K个点连起来,使得链的总长最短.可以随意选择要链的点.n=100000. 这道题居然可以用堆-- 首先,不能把区 ...

  6. spoj Longest Common Substring

    Longest Common Substring SPOJ - LCS 题意:求两个串的最长公共子串 /* 对一个串建立后缀自动机,用另一个串上去匹配 */ #include<iostream& ...

  7. Nginx服务优化配置

    1.expires缓存模块 具体配置可参考官方文档 http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires [root@c ...

  8. 平衡树学习笔记(3)-------Splay

    Splay 上一篇:平衡树学习笔记(2)-------Treap Splay是一个实用而且灵活性很强的平衡树 效率上也比较客观,但是一定要一次性写对 debug可能不是那么容易 Splay作为平衡树, ...

  9. java8 optional操作

    目标:测试option的过滤,链式操作: 代码: package test; import java.util.ArrayList; import java.util.Arrays; import j ...

  10. lambda函数/排序/filter/map

    1.lambda 匿名函数 zrf = lambda x:x**2 ret = zrf(10) #这里面实际上还是有函数名 print(ret) 2.sorted 排序(list也自带排序功能) 排序 ...