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 "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的更多相关文章
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- hbase-shell + hbase的java api
本博文的主要内容有 .HBase的单机模式(1节点)安装 .HBase的单机模式(1节点)的启动 .HBase的伪分布模式(1节点)安装 .HBase的伪分布模式(1节点)的启动 .HBas ...
- c++关键字explicit
关键字explicit,可以阻止不应该允许的经过转换构造函数进行的隐式转换的发生.声明为explicit的构造函数不能在隐式转换中使用. C++中, 一个参数的构造函数(或者除了第一个参数外其余参数都 ...
- 跟我一起玩Win32开发(19):浏览和打开文件
在应用程序中,我们很经常要实现的功能,是Open文件或保存文件对话框,让用户来选择一个或N个文件.本文我将介绍两种思路,第一种方法较为复杂,第二种方法较为简单. 方法一:老规矩 这是一种传统方法,使用 ...
- Qt之对话框QDialog
这一节主要讲述对话框类,先讲述两种不同类型的对话框,再介绍Qt提供的几个标准对话框.对应本节的内容,可以在帮助索引中查看 QDialog 和 Dialog Windows 关键字. 一.模态和非模态对 ...
- PHP使用curl函数实现多种请求(post,get)
PHP使用curl函数实现get,post请求 一.CURL介绍 CURL是一个非常强大的开源库,支持很多协议,包括HTTP.FTP.TELNET等,我们使用它来发送HTTP请求.它给我 们带来的好处 ...
- 为页面添加favicon
<link rel="shortcut icon" href="favicon.ico" /> 还有另一种写法,但是IE对它的支持不够好: < ...
- PV,UV,IP概念
PV是网站分析的一个术语,用以衡量网站用户访问的网页的数量.对于广告主,PV值可预期它可以带来多少广告收入.一般来说,PV与来访者的数量成正比,但是PV并不直接决定页面的真实来访者数量,如同一个来访者 ...
- 解决vue跨域问题
package com.qmtt.config; import java.io.IOException; import javax.servlet.Filter; import javax.servl ...
- AJPFX的内存管理小结
管理范围:任何继承于 NSObject的对象原理:每一个对象都有引用计数器当使用alloc new 和 copy创建对象时引用计数器被设置为1给对象发送一条retain消息 ,引用计数器加1 ...
- iOS 二维码扫描 通过ZBar ZXing等第三方库
扫描二维码的开源库有很多如 ZBar.ZXing等 ZBar的使用方法: 下载ZBar SDK 地址https://github.com/bmorton/ZBarSDK ZBarSDK是一个开源的SD ...