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 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的更多相关文章
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 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 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- git 使用笔记(一)
1. 环境介绍 windows10 2.使用 2.1 安装git for windows 2.2 创建一个文件夹, 开始git管理 2.3 查看该目录,包括隐藏文件 2.4 把testgit.txt添 ...
- bootstrap 学习片段
1. 只要单击按钮添加了data-toggle="dropdown"属性, 在单击按钮的时候,默认隐藏的下拉列表就会显示出来 <div class="row&quo ...
- 【JavaEE】SSH+Spring Security自定义Security的部分处理策略
本文建立在 SSH与Spring Security整合 一文的基础上,从这篇文章的example上做修改,或者从 配置了AOP 的example上做修改皆可.这里主要补充我在实际使用Spring Se ...
- js实现轮播
在我们准备动手之前先了解下几个属性 dom元素的位置的几个相关属性 dom元素宽度/高度 clientWidth/clientHeight 元素的内尺寸 content + padding ...
- 数码管问题(c++实现)
描述:液晶数码管用七笔阿拉数字表示的十个数字,把横和竖的一 个短划都称为一笔,即7有3笔,8有7笔等.对于十个数字一种排列,要做到 两相邻数字都可以由另一个数字加上几笔或减去几笔组成,但不能又加又减. ...
- VisualStudio中解决方案
在VS中创建一个项目通常会生成一个解决方案文件(.sln)和一个隐藏的解决方案用户选项文件(.suo). 解决方案文件是一个文本文件,包含以下信息: 将被加载的所有项目以构成完整解决方案的项目清单 解 ...
- cl_gui_cfw=>flush
用法一: REFRESH_TABLE_DISPLAY虽然刷新的界面,但是SAP GUI并不是实时更新,而是将更新的结果放在缓存中,手动调用CL_GUI_CFW=>FLUSH才能触 ...
- Error occurred in deployment step 'Add Solution': Operation is not valid due to the current state of the object.
Sharepoint 部署的时候出现一个错误 Error occurred in deployment step 'Add Solution': Operation is not valid due ...
- 中国象棋引擎的C#源代码
以前写的中国象棋引擎的C#源程序,可在VS2010中编译运行,由于个人精力有限,难以完成后续的开发工作,如果谁感兴趣,请关注微信公众号(“申龙斌的程序人生”,ID:slbGTD),发送后台消息“象棋引 ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q125-Q126)
Question 125You are creating an application for SharePoint Server 2010.The application will run on a ...