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 ...
随机推荐
- PHP OAuth2 Server库
想找比较正宗的库,查了蛮久的.最后在 oauth官方站上,看到PHP版本的相关链接. 发现都是php 5.3版本以上的环境,基于命名空间的写法编写的. 访问下面这个页面,难得,发现文档给出了5.2版本 ...
- 【GOF23设计模式】组合模式
来源:http://www.bjsxt.com/ 一.[GOF23设计模式]_组合模式.树状结构.杀毒软件架构.JUnite底层架构.常见开发场景 package com.test.composite ...
- 原型 prototype
原型 prototype js 的对象比较 由于 js 是解释执行的语言, 那么再代码中出现函数与对象如果重复执行, 会创建多个副本 在代码中重复执行的代码容易出现重复的对象 创建一个 Person ...
- 用单例模式封装常用方法 utils class v1.0
utils class v1.0:The common methods used in our JS are included. * by sarah on 2016/01/28 var utils ...
- margin:0 auto;不能居中的原因
原因: 1.没有设置本身元素和父元素的宽度 2.本身元素使用了绝对定位和浮动 2.没声明DOCTYPE
- REUSE_ALV_GRID_DISPLAY显示ALV,设置可编辑时,与内表数据同步问题
使用function module: REUSE_ALV_GRID_DISPLAY显示ALV,并设置alv某些列可编辑,可是编辑后发现对应的内表数据并没有随之改变.记得需要设置一个参数的值,怎么想也记 ...
- SAP和Java系统的Webservice实例
简介: 关于Webservice的概念和原理,简单来讲,Webservice是一种基于SOAP传输协议,用WSDL描述,用XML封装数据的接口技术.由于其跨平台.跨防火墙.开发成本低.开发周期短等优势 ...
- 404 & 401 Errors with the App Management Service
from:http://blogs.technet.com/b/sharepoint_-_inside_the_lines/archive/2013/06/23/404-amp-401-errors- ...
- MVC中的CSRF解决方案
我们使用Ajax访问请求的时候,攻击者可能盗用了用户身份,以用户合法身份发送恶意请求. 具体预防措施, 1.在Html表单里面使用@Html.AntiForgeryToken(),这玩意会生成一对加密 ...
- SeismicPro地震剖面显示程序
SeismicPro是一个地震剖面显示软件,可从标准SEGY地震数据体中抽取纵测线和横测线的二维剖面,并以波形.变面积和变密度等多种方式进行专业化显示,可进行一键式显示方式切换,并可进行定制开发叠加井 ...