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 ...
随机推荐
- 【转】oracle Sequence
http://blog.csdn.net/zhoufoxcn/article/details/1762351 在oracle中sequence就是序号,每次取的时候它会自动增加.sequence与表没 ...
- css实现的透明三角形
css实现下图样式,具体像素值记不住了,很好设置,html code (2014百度秋招面试题): <div id="demo"></div> 分析:这 ...
- 转 mysql 中sql 语句查询今天、昨天、7天、近30天、本月、上一月 数据
转自 http://blog.csdn.net/ve_love/article/details/19685399
- WF工作流与管理类应用系统工作流需求实现的一些误区
如今实现各种应用系统大家都知道工作流是一个非常重要的环节,不同的业务系统的工作流需求是需要找相应的工作流产品去实现的,因为不同工作流产品的架构细节也许会成为某类需求实现的瓶颈. WF ...
- C语言2048
这段时间google上有个小游戏挺火的,我也很喜欢,业余时间做个C语言版的. 老规矩先上干货: http://files.cnblogs.com/GhostZCH/2048.rar (.c & ...
- 定位 - CoreLocation - 指南针
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...
- APNs-远程推送
一.开发iOS程序的推送功能, iOS端需要做的事 1.请求苹果获得deviceToken 2.得到苹果返回的deviceToken 3.发送deviceToken给公司的服务器 4.监听用户对通知的 ...
- C++返回引用的函数
要以引用返回函数值,则函数定义时的格式如下: 类型标识符&类型名 (形参列表及类型说明) { 函数体 } 用const限定引用的声明方式为: const 类型标识符&引用名=目标变量名 ...
- 导入旧版本Android项目时的“Unable to resolve target ‘android
在Ecplise + ATD + Android SDK的开发中,导入旧版本的Android项目时,往往会出现类似的如下错误 Error:Unable to resolve target 'andro ...
- hdu 2460
这是一道双联通分量的题,要用到LCA算法: 听说这个算法有两种实现方式:一个是dfs+线段树或着RMQ;一个是用tarjin: 我用的是tarjin: 题目比较简单,就是每次加了一条边之后剩下的桥的个 ...