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 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, andDD, 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
#include "iostream"
#include "math.h"
using namespace std;
int n, m;
#define MINLEN 42.5
struct Pointer {
int x;
int y;
}p[];
bool answer = false; /* 记录007能否安全逃生~~ */
bool visited[] = {false}; /* 判断当前点是否被访问过 */ bool isSave(int x) { /* 判断从当前点能否跳到岸上 */
if ((p[x].x - m <= -) || (p[x].x + m >= ) || (p[x].y - m <= -) || (p[x].y + m >= ))
return true;
return false;
} bool jump(int x, int y) { /* 判断2个点距离是否在跳跃能力内 */
int p1 = pow(p[x].x - p[y].x, );
int p2 = pow(p[x].y - p[y].y, );
int r = m * m;
if (p1 + p2 <= r)
return true;
return false;
} bool firstJump(int x) { /* 当007处于孤岛时 第一次可以选择跳的鳄鱼 因为第一次判断能否跳跃的计算方法与后面dfs不相同 所以要单独写 */
int p1 = pow(p[x].x , );
int p2 = pow(p[x].y , );
int r = (m+7.5) * (m+7.5);
if (p1 + p2 <= r) {
return true;
}
return false;
}
bool dfs(int x) { /* 深搜 */
visited[x] = true;
if (isSave(x)) {
answer = true;
}
for (int i = ; i < n; i++) {
if (!visited[i] && jump(x, i)) /* 没访问过 并且在跳跃能力之内 */
{
answer = dfs(i);
if (answer == true)
break;
}
}
return answer;
}
int main() {
cin >> n >> m;
for (int i = ; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
if (m >= MINLEN) { /* 可以直接从孤岛上提到岸上 直接输出 */
cout << "Yes" << endl;
return ;
}
for (int i = ; i < n; i++) {
if (firstJump(i) && !visited[i]) { /* 如果第一次能够跳的 并且之前没有访问过的节点 则深搜该节点 */
if (dfs(i))
break;
}
}
if (answer == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
return ;
}
PTA 06-图2 Saving James Bond - Easy Version (25分)的更多相关文章
- 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 作 ...
- pta 编程题16 Saving James Bond - Easy Version
其它pta数据结构编程题请参见:pta 题目 主要用到了深度优先搜索. #include <iostream> using namespace std; struct Vertex { i ...
- 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 ...
随机推荐
- c++ explicit 用法摘抄
笔记 //Student.h[explicit修饰] Student (int n): Student doh(); doh = ; //没有 explicit=>doh = Student(5 ...
- ECharts使用记
系统开发厂商一直都使用基于Flash的图表解决方案,例如Fushioncharts.本人也曾略做研究,当时对js不熟,只能采用静态xml方式,颇为繁琐. 自从了解了html5的新特性,意识到基于Can ...
- Android 自定义View实现单击和双击事件
自定义View, 1. 自定义一个Runnable线程TouchEventCountThread , 用来统计500ms内的点击次数 2. 在MyView中的 onTouchEvent 中调用 上面 ...
- #Leet Code# Convert Sorted Array to Binary Search Tree
描述:递归 代码: class Solution: # @param num, a list of integers # @return a tree node def sortedArrayToBS ...
- 【转】ant命令总结
http://feiyeguohai.iteye.com/blog/1295922 ant命令总结 1 Ant是什么? Apache Ant 是一个基于 Java的生成工具. 生成工具在软件开发中用 ...
- Mac下获取AppStore安装包文件路径
通过远在大洋彼岸的苹果服务器下载东西,确实有够慢啊!AppStore更甚:甚至都经常提示连不上服务器,而有些软件呢,还必须从AppStore下载安装,所以没办法,谁让上了苹果的贼船呢!公司的网速更是不 ...
- YUV数据格式
概要: 与RGB编码方法类似,YUV也是一种颜色编码方法,主要用于电视系统以及模拟视频领域,它是指将亮度参量(Y:Luminance或Luma)和色度参量(UV:Chrominance或Chroma) ...
- Session里的对象是不可靠的!
最近在做Database课程的final project,foodiePharos, 重新认识了JSP里容易出现的一些问题. 比如我们这个项目使用了JPA,就涉及到entity对象的状态问题,Enti ...
- phpstorm 强大的活动模板 可以自定义注释,代码段,根据cms订制自动提示
http://jingyan.baidu.com/article/8275fc86badd6346a03cf6aa.html [PHP] phpstorm的使用(1) http://v.youku.c ...
- Android 拖动条(SeekBar)实例 附完整demo项目代码
1.拖动条的事件 实现SeekBar.OnSeekBarChangeListener接口.需要监听三个事件:数值改变(onProgressChanged)开始拖动(onStartTrackingTou ...