题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625

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 N (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (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 <cstdio>
#include <cmath>
#include <cstdlib> const double ISLAND_RADIUS = 15.0 / ; //孤岛半径
const double SQUARE_SIZE = 100.0; //湖(正方形)的大小
const int N = ; //鳄鱼(点)的最大数 typedef struct Point
{
double x, y;
} Position; Position P[N];
bool Visited[N];
int n;
double d; void Save007();
bool DFS(int V);
bool FirstJump(int V);
bool Jump(int V1, int V2);
bool IsSave(int V); int main()
{
scanf("%d%lf", &n, &d);
for (int i = ; i < n; i++)
scanf("%lf%lf", &(P[i].x), &(P[i].y)); for (int i = ; i < n; i++)
Visited[i] = false;
Save007(); return ;
} void Save007()
{
bool IsSave = false;
for (int i = ; i < n; i++)
{
if (!Visited[i] && FirstJump(i))
{
IsSave = DFS(i);
if (IsSave)
break;
}
}
if (IsSave)
printf("Yes\n");
else
printf("No\n");
} bool DFS(int V)
{
Visited[V] = true;
bool answer = false;
if (IsSave(V))
return true;
for (int i = ; i < n; i++)
{
if (!Visited[i] && Jump(V, i))
answer = DFS(i);
if (answer)
break;
}
return answer;
} bool IsSave(int V)
{
return (abs(P[V].x) >= - d)
|| (abs(P[V].y) >= - d);
} bool FirstJump(int V)
{
return sqrt(P[V].x * P[V].x + P[V].y * P[V].y)
<= d + ISLAND_RADIUS;
} bool Jump(int V1, int V2)
{
return sqrt((P[V1].x - P[V2].x) * (P[V1].x - P[V2].x) +
(P[V1].y - P[V2].y) * (P[V1].y - P[V2].y))
<= d;
}

06-图2 Saving James Bond - Easy Version的更多相关文章

  1. Saving James Bond - Easy Version (MOOC)

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

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

  4. PAT Saving James Bond - Easy Version

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

  5. 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 Bon ...

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

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

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

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

随机推荐

  1. NoSuchMethodException <init>()

    1. Question Description: SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/n ...

  2. PHP的静态变量和引用函数

    直接贴代码,结果的原因写在备注了 <?php /** * Created by PhpStorm. * User: Administrator * Date: 16-8-25 * Time: 上 ...

  3. Bootstrap 我的学习记录2 栅格系统初识

    以下理论内容copy自bootstrap中文网(一个不错的bootstrap学习网站). 栅格系统 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport) ...

  4. CRM行编辑控件

    原创,转载请说明出处 王红福 http://www.cnblogs.com/hellohongfu/p/4792452.html CRM 本身的表格可以根据定义显示列信息,但是出于性能考虑不能详细的展 ...

  5. Sharepoint 2013 关于"SPChange"简介

    在SharePoint中,我们经常会需要获取那些改变的项目,其实api为我们提供了SPChange对象,下面,我们通过列表简单介绍下这一对象. 1.创建一个测试列表,名字叫做“SPChangeItem ...

  6. sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

    现象: sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户 处理办法: 1.Open the Exchange Management Shell 2.输入: New-Mana ...

  7. Installation failed with message INSTALL_FAILED_UID_CHANGED.--APK安装失败解决方法

    出现此错误原因大都为:手机上原来APK存在残留,即没有卸载干净,导致不能安装新的APK 解决办法: 1.手机上手动卸载出现问题的APP,再重新安装 2.如果apk无法卸载,则将apk相关文件和相关内容 ...

  8. Fresco 使用笔记(一):加载gif图片并播放

    项目总结 --------------------------------------------------------------------- 前言: 项目中图文混合使用的太多太多了,但是绝大部 ...

  9. Activity与Fragment的生命周期

    今天看到一张图,详细描述了Activity和Fragment的生命周期,好资源共享咯!

  10. IOS 二维码生成

    这篇博客将会介绍二维码的生成. 由于没有什么东西值得长篇大论的,所以这里我就通过代码的实现介绍二维码. 第一部分 第一部分是二维码的简单生成没有其他重点介绍. 效果图 代码部分 // // ViewC ...