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 ...
随机推荐
- 设置用户sudo -s拥有root权限
开通普通用户的ROOT权限,上线了可以禁止用户使用root权限 修改配置文件 vi etc/sudoers 在 root ALL=(ALL) ALL那么你就在下边再加一条配置:hjd ALL=( ...
- php练习5——简单的学生管理系统(隐藏控件的使用)
要求: 程序:gradeManage.html和gradeManage.php 结果 注意: 1.使用隐藏控件时,得在不同表单下,不能在同一个表单下: 2. ...
- C语言-06复杂数据类型-03指针
指针变量的定义 变量类型 *变量名; #include <stdio.h> int main() { // 指针就一个作用:能够根据一个地址值,访问对应的存储空间 // 指针变量p前面的i ...
- 解决vsftpd 2.2.2读取目录列表失败的问题
该错误是由iptables的配置引起的,临时的解决方法是执行如下命令: [root@localhost soft]# modprobe ip_nat_ftp 再次登陆列表正常啦! 但当你重新启动服务器 ...
- Spring之Spring MVC
Spring调配半天没搞定,原来是web.xml应该放在WEB-INF的目录下,而不是webcontent目录下: java.lang.ClassNotFoundException: org.spri ...
- js带缩略图的图片切换效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C语言利用va_list、va_start、va_end、va_arg宏定义可变参数的函数
在定义可变参数的函数之前,先来理解一下函数参数的传递原理: 1.函数参数是以栈这种数据结构来存取的,在函数参数列表中,从右至左依次入栈. 2.参数的内存存放格式:参数的内存地址存放在内存的堆栈段中,在 ...
- 深入浅出Z-Stack 2006 OSAL多任务资源分配机制
转自深入浅出Z-Stack 2006 OSAL多任务资源分配机制 一.概述 OSAL (Operating System Abstraction Layer),翻译为"操作系统抽象层&quo ...
- 在安全层面,企业如何获得更好的投资回报率 ROI?
前言 任何企业对投资都有回报的要求,回报可能是直接的「利润」,达到短期.长期的目标,或者通过投资减少损失.因此每个项目的决策者在每笔投资前都要衡量 ROI,证明该投资能达到的效果和收益,以便在项目结束 ...
- Docker日志自动化: ElasticSearch、Logstash、Kibana以及Logspout
http://www.open-open.com/lib/view/open1432107136989.html