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 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<iostream>
#include<math.h>
#include<vector>
using namespace std;
#define MaxN 101
int flag=;
vector<int> visited(MaxN,);
struct node{
int x;
int y;
};
struct Gnode{
int N;
int D;
node G[MaxN];
};
using Graph=Gnode*;
Graph buildGraph(){
int N,D,x,y;
cin>>N>>D;
Graph gra=new Gnode();
gra->N=N; gra->D=D;
gra->G[].x=; gra->G[].y=;
for(int i=;i<=gra->N;i++){
cin>>x>>y;
gra->G[i].x=x; gra->G[i].y=y;
}
return gra;
}
double distance(node n1,node n2)
{
return sqrt((n1.x-n2.x)*(n1.x-n2.x)+(n1.y-n2.y)*(n1.y-n2.y));
}
int finish(Graph gra,int v){
if(gra->G[v].x>=-gra->D)
{flag=;return ;}
if(gra->G[v].x<=-+gra->D)
{flag=;return ;}
if(gra->G[v].y>=-gra->D)
{flag=;return ;}
if(gra->G[v].y<=-+gra->D)
{flag=;return ;}
return ;
}
void DFS(Graph gra,int v){
visited[v]=;
if(finish(gra,v))
return;
for(int i=;i<=gra->N;i++)
if(visited[i]!=&&distance(gra->G[i],gra->G[v])<=gra->D)
DFS(gra,i);
}
void Givenanswer(Graph gra){
int v;
if(gra->D>=)
flag=;
for(v=;v<=gra->N;v++){
if(flag==){ //cout<<distance(gra->G[v],gra->G[0])-7.5<<endl;
if(visited[v]!=&&distance(gra->G[v],gra->G[])-<=gra->D)
{ DFS(gra,v);}
} }
if(flag==) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int main()
{
Graph gra=buildGraph();
Givenanswer(gra);
return ;
}

Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33的更多相关文章

  1. Saving James Bond - Easy Version (MOOC)

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

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

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  3. PAT Saving James Bond - Easy Version

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

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

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

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

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

  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. mui.init()方法中可以有子页面和预加载两项内容,它们是否都在页面加载完成时创建其对应的webview对象?

    subpages和preloadPages区别是什么? mui.init({ subpages: [{ url: 'subject.html', //子页面HTML地址,支持本地地址和网络地址 id: ...

  2. python之类的相关名词解释

    变量:在类里面定义的变量,不必实例化即可调用 实例变量:在类里面定义的变量,必须实例化之后才可以调用 比如: 属性方法:调用时看起来像是一个变量,方法没有入参,可以变成一个属性方法 在方法上添加@pr ...

  3. BZOJ4653(区间离散化+线段树+决策单调尺取)

    写得很好的题解 一眼过去很像是:排序,然后从前向后扫,有这个区间时插到树里,过去以后再删除.然后事实也是这样做的…… 具体起来: 1.如果考虑暴力的话,一种想法是枚举左端和右端要选取的区间(如果我们按 ...

  4. Tomcat启动后打开页面提示404错误的解决

    Eclipse配置并启动Tomcat成功,但有时会访问localhost:8080出现404错误,此时需要修改Tomcat配置.步骤如下: 在Eclipse中双击Tomcat server,打开Tom ...

  5. h5-18-文件操作-兼容判断

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. MySql数据基本操作sql语句

    表字段 1>插入数据insert 如果不插入id,让id自动增加 INSERT INTO `gpw_group`(group_code, group_parent_id, group_name, ...

  7. CentOS 6.9 --Squid代理服务器

    主机名 IP地址  网关   DNS   服务类型  Master eth0:192.168.17.130(VMnet4) eth1:192.168.30.130(NAT) 192.168.30.2 ...

  8. [转]IntelliJ IDEA 自定义方法注解模板

    IntelliJ IDEA 自定义方法注解模板 置顶2017年08月02日 18:04:36 阅读数:32592 最近没啥事开始正式用Eclipse 转入 idea工具阵营,毕竟有70%的开发者在使用 ...

  9. 责任链模式和php实现

    职责链模式(又叫责任链模式): 包含了一些命令对象和一些处理对象,每个处理对象决定它能处理那些命令对象,它也知道应该把自己不能处理的命令对象交下一个处理对象,该模式还描述了往该链添加新的处理对象的方法 ...

  10. iOS 随笔小技巧 弱self 打印当前类行数列数,多人开发自动适配pch地址,获取设备uid的信息

    $(SRCROOT)/PrefixHeader.pch自动适配pch地址 __weak __block typeof(self) weakself = self; __weak typeof(self ...