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. GUID介绍

    GUID介绍 GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制 ...

  2. C#读取文本文件某一行

    某一时候,我们只会读取文本文件内某一行.怎样读?还是用for或foreach循环?其实操作起来,很简单,先看看文本文件,如果你也想用下面的文档来做测试,你可以在这个链接进行拷贝:<VB.NET提 ...

  3. 实现简易Web服务器(c语言)

    任务: (1)实现服务器与客户端间的通信. (2)可以实现HTTP请求中的GET方法. (3)提供静态网页浏览功能,如可浏览:HTML页面,无格式文本,常见图像格式等. (4)提供可以传递参数的动态网 ...

  4. git pull 命令

    作用:取回远程主机某个分支的更新,再与本地的指定分支合并 格式:git pull  <远程主机名> <远程分支名>:<本地分支名> 1. 如果与当前分支合并,则可省 ...

  5. loj #2006. 「SCOI2015」小凸玩矩阵

    #2006. 「SCOI2015」小凸玩矩阵   题目描述 小凸和小方是好朋友,小方给小凸一个 N×M N \times MN×M(N≤M N \leq MN≤M)的矩阵 A AA,要求小凸从其中选出 ...

  6. loj#6363. 「地底蔷薇」(拉格朗日反演+多项式全家桶)

    题面 传送门 题解 肝了一个下午--我老是忘了拉格朗日反演计算的时候多项式要除以一个\(x\)--结果看它推倒简直一脸懵逼-- 做这题首先你得知道拉格朗日反演是个什么东西->这里 请坐稳,接下来 ...

  7. Python之‘数据结构’

    简介 数据结构基本上就是--它们是可以处理一些数据的结构.或者说,它们是用来存储一组相关数据的.在Python里面有三种内建的数据结构--列表.元组和字典. 一.列表 list是处理一组有序项目的数据 ...

  8. cuda编程知识普及

    本帖经过多方整理,大多来自各路书籍<GPGPU编程技术><cuda高性能>   1 grid 和 block都可以用三元向量来表示:   grid的数组元素是block blo ...

  9. win10全半角切换

    shift+sapce shift+sapce:全半角切换快捷键,编程的时候发现英文是这种状态,就需要用快捷键切换成半角. (查过老是忘记,在这里写一下记住它)

  10. C++基础学习7:new/delete操作符

    在C语言中,动态分配和释放内存的函数是malloc.calloc和free,而在C++语言中,new.new[].delete和delete[]操作符通常会被用来动态地分配内存和释放内存. 需要注意的 ...