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分)的更多相关文章

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

  2. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  3. pta 编程题16 Saving James Bond - Easy Version

    其它pta数据结构编程题请参见:pta 题目 主要用到了深度优先搜索. #include <iostream> using namespace std; struct Vertex { i ...

  4. 05-图2. Saving James Bond - Easy Version (25)

    1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...

  5. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

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

  7. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

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

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

随机推荐

  1. epoll和select区别

    先说下本文框架,先是问题引出,然后概括两个机制的区别和联系,最后介绍每个接口的用法 一.问题引出 联系区别 问题的引出,当需要读两个以上的I/O的时候,如果使用阻塞式的I/O,那么可能长时间的阻塞在一 ...

  2. centos下redis安装

    下载redis http://www.redis.cn/download.html 下载php的redis扩展 https://github.com/phpredis/phpredis#install ...

  3. osg(OpenSceneGraph)学习笔记1:智能指针osg::ref_ptr<>

    OSG的智能指针,osg::ref_ptr<> osg::Referenced类管理引用计数内存块,osg::ref_ptr需要使用以它为基类的其它类作为模板参数. osg::ref_pt ...

  4. How to get Directory size in IsolatedStorage of Windows Phone 8 App

    There is no API to get the total size of a specific directory in the isolated storage. Therefore, th ...

  5. C语言中字符型和字符串型的区别?

    C语言中只有字符型类型,没有字符串型类型.字符类型用一个带符号的8位二进制编码表示,其性质与int相同,只是只有一个字节.表示字符的ASCII编码使用其中的0~127,所以要明白字符类型(char)其 ...

  6. MINA源码分析

    IoService通过构造函数的形式成为了IoSession一部分,IoSession是通过IoAcceptor以及connector创建出来,这二者其实就是IoService,所以对于IoSessi ...

  7. iOS 静态库中使用宏定义区分iPhone模拟器与真机---备用

    问题描述 一般项目中,可以使用宏定义来判断模拟器还是真机,这无疑是有效的. #if TARGET_IPHONE_SIMULATOR #define SIMULATOR 1 #elif TARGET_O ...

  8. PHP错误Warning: Cannot modify header information - headers already sent by解决方法

    这篇文章主要介绍了PHP错误Warning: Cannot modify header information - headers already sent by解决方法,需要的朋友可以参考下 今天在 ...

  9. 15 个响应式的 jQuery 图像滑块插件

    设计师和开发人员总是试图使用新技术让网站更智能,而我们发现在许多网站上 jQuery 的图像滑块插件是非常受欢迎的.本文继续介绍 15 个 jQuery 图像滑块插件以供您选择. ELASTISLID ...

  10. sharepoint 2013 安装配置PowerView

    安装sharepoint 2013 网络上有很多说明.这里列出两个实例: 1.说得比较详细,并提供了下载连接:http://www.sqlant.com/2012/10/sharepoint-2013 ...