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<cstdio>
- #include<cmath>
- #include<cstdlib>
- const double ISLAND_RADIUS = 15.0 / ;
- const double SQUARE_SIZE = 100.0;
- const int maxn = ;
- typedef struct Point{
- double x,y;
- }Position;
- Position P[maxn];
- int n;
- double d;
- bool vis[maxn];
- void save007();
- bool FirstJump(int v);
- bool DFS(int v);
- bool isSave(int v);
- bool Jump(int v1,int v2);
- int main(){
- scanf("%d %lf",&n,&d);
- for(int i = ; i < n; i++){
- scanf("%lf %lf",&(P[i].x),&(P[i].y));
- }
- for(int i = ; i < n; i++){
- vis[i] = false;
- }
- save007();
- return ;
- }
- void save007(){
- bool isVist = false;
- for(int i = ; i < n; i++){
- if(!vis[i] && FirstJump(i)){
- isVist = DFS(i);
- if(isVist) break;
- }
- }
- if(isVist) printf("Yes\n");
- else printf("No\n");
- }
- bool FirstJump(int v){
- return sqrt(P[v].x * P[v].x + P[v].y * P[v].y) <= d + ISLAND_RADIUS;
- }
- bool DFS(int v){
- bool answer = false;
- vis[v] = true;
- if(isSave(v)) return true;
- for(int i = ; i < n; i++){
- if(!vis[i] && Jump(v,i)){
- answer = DFS(i);
- }
- if(answer) break;
- }
- return answer;
- }
- bool isSave(int v){
- return (abs(P[v].x) >= - d) || (abs(P[v].y) >= - d);
- }
- bool Jump(int v1,int v2){
- return sqrt((P[v1].x - P[v2].x)*(P[v1].x - P[v2].x) + (P[v1].y - P[v2].y) * (P[v1].y - P[v2].y)) <= d;
- }
06-图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 ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 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 ...
- PTA 07-图5 Saving James Bond - Hard Version (30分)
07-图5 Saving James Bond - Hard Version (30分) This time let us consider the situation in the movie ...
- 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 ...
随机推荐
- Xcode快捷
- java多线程编程——同步器Exchanger
类java.util.concurrent.Exchanger提供了一个同步点,在这个同步点,一对线程可以交换数据.每个线程通过exchange()方法的入口提供数据给他的伙伴线程,并接收他的伙伴线程 ...
- 恢复oracle的回收站的所有的表
使用sys as sysdba 进入到sqlplus的控制界面 sqlplus / as sysdba 执行相关的命令,自动生成一个脚本文件 spool d:/a.sql select 'flashb ...
- 推荐两款富文本编辑器:NicEdit和Kindeditor
做过Web开发的朋友相信都使用过富文本编辑器,比较出名的CuteEditor和CKEditor很多人应该已经使用过,在功能强大的同时需要加载的东西也变得很多.下面要推荐的两款富文本编辑器都是使用JS编 ...
- java网络编程安全问题
客户端与服务器互相传输时传输的数据的原内容会不会被人获取到? 在客户端与服务器之间有很多通信节点,数据在这些节点上传输前,可以先获取他们的安全证书,至于当心怕被修改可以用SSL加密(个人见解,这方面懂 ...
- pecl的使用
1. 安装方法 : pecl install packagename, 安装目录在/usr/local/php7/lib/php/extensions 例如:pecl install sealog 2 ...
- c语言学习笔记 const变量
在c语言的编程过程中经常会遇到有常数参加运算的运算,比如这种. int a=100*b; 这个100我们叫常数或者叫常量,但是程序中我们不推荐这种直接写常数的方法,有两个缺点. 第一是程序可读性差. ...
- Android调试之Logcat
转贴 http://www.cnblogs.com/adison/p/4264284.html 在Android开发过程中,总免不了要调试,无论是Debug,还是Android自带的Logcat,抑 ...
- Entity Framework Tutorial Basics(31):Migration from EF 4.X
Migration from Entity Framework 4.1/4.3 to Entity Framework 5.0/6.0 To migrate your existing Entity ...
- SQL SERVER 取本月上月日期
select dateadd(dd,-day(dateadd(month,-1,getdate()))+1,dateadd(month,-1,getdate())) /*上个月一号*/ s ...