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 NN (\le 100≤100), the number of crocodiles, and DD, the maximum distance that James could jump. Then NN lines follow, each containing the (x, y)(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

简单的图的遍历,就当作是对DFS新手的练习吧,使用数组更方便一些,当然我是看了别人的代码才有的思路。。

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n,r;
double a[200];
int visited[200];
bool IsSafe(double d){if(50-d<=r){return true;}else{return false;}
}
bool FirstJump(double d){if(d<=r+15/2){return true;}else{return false;}
}
bool Jump(double d1,double d2){if(abs(d1-d2)<=r){return true;}else{return false;}
}
int DFS(int i){visited[i]=1;int flag=0;if(IsSafe(a[i])){flag=1;}for(int j=0;j<=n;j++){if(Jump(a[j],a[i])&&!visited[j]){flag=DFS(j);}if(flag==1){break;}}return flag;
}
int main(){cin>>n>>r;int i,x,y,flag;for(i=0;i<n;i++){cin>>x>>y;a[i]=sqrt(x*x+y*y);}for(int i=0;i<n;i++){if(FirstJump(a[i])&&!visited[i]){flag=DFS(i);if(flag==1){break;}}}if(flag==1){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}return 0;
}

Saving James Bond - Easy Version相关推荐

  1. PTA 06-图2 Saving James Bond - Easy Version (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/672 5-10 Saving James Bond - Easy Version   ( ...

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

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

  4. 六、图(上):Saving James Bond - Easy Version

    目录 题目描述 代码 注意事项 题目描述 This time let us consider the situation in the movie "Live and Let Die&quo ...

  5. 中国大学MOOC-陈越、何钦铭-数据结构 Saving James Bond - Easy Version

    题目描述: This time let us consider the situation in the movie "Live and Let Die" in which Jam ...

  6. 算法 图2 Saving James Bond - Easy Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案汇总 题目:This time let us consider the situation in the movie & ...

  7. 图5 Saving James Bond - Hard Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案 题目:This time let us consider the situation in the movie &qu ...

  8. (c语言)Saving James Bond - Hard Version (30分)

    关于数据结构Mooc后的每一道答案 基本我都已经给出了详解 希望能对大家有所帮助 收藏一下也是方便大家查找吧 希望大家一起进步! (c语言)浙大数据结构Mooc作者答案集 原题题目(谷歌翻译) 全检查 ...

  9. 07-图4. Saving James Bond - Hard Version (30)

    本题测试点5是从小岛范围内可以直接跳到岸边-- 测试点4是验证步数第一跳最小的情况,刚开始没有考虑回溯,所以错了-- #include <stdio.h> #include <str ...

最新文章

  1. 记一次CPU占用率和load高的排查
  2. 什么是标准输入,标准输出(stdin,stdout)
  3. MyBatis(4)动态SQL
  4. 监控摄像头卡顿_视频监控系统施工六大注意事项
  5. .net 下语音合成
  6. C++ static关键字
  7. Zend Studio使用教程:序列号注册
  8. 【BZOJ2584】memory,扫描线+拓扑图+骗
  9. Oracle start with.connect by prior子句实现递归查询
  10. BZOJ-3227 红黑树(tree) 树形DP
  11. prerenderspaplugin可以抓取动态数据吗_RPA编程思路之数据抓取
  12. 二十个JAVA程序代码
  13. 冷高轮时间王思聪吃热狗windows电脑壁纸下载
  14. 微信支付(小程序)-商户号配置与小程序配置
  15. 微信服务器会留撤回的消息吗,让你的微信不再被人撤回消息
  16. 计算机考试照片是一寸,怎么用电脑拍照片_怎么用电脑将照片修成一寸大小
  17. Python小黄人绘制
  18. react hook 闭包陷阱问题
  19. TQ2440 mifi驱动及开机自动连接wifi全过程
  20. DMOZ网站选择标准(转)

热门文章

  1. TCP多人聊天程序Java实现(群聊,私聊,在线用户,踢出用户)
  2. cordova vue ios调用camera拍照保存图片时闪退 iOS11之后
  3. 0.前言——章节目录链接与为何要写这个?
  4. Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)
  5. python 长整型_Python整型运算之布尔型、标准整型、长整型操作示例
  6. php读取文件行读,如何在php中按行读取文件
  7. 软件测试--QQ状态(PICT测试工具生成决策表)
  8. python抓包拦截_python实现抓包、解析流程,超过瘾!
  9. 解读人生的四种汉堡模型
  10. 如何为mysql建立索引