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 / 2; //孤岛半径
const double SQUARE_SIZE = 100.0; //湖(正方形)的大小
const int N = 110; //鳄鱼(点)的最大数
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 = 0; i < n; i++)
scanf("%lf%lf", &(P[i].x), &(P[i].y));
for (int i = 0; i < n; i++)
Visited[i] = false;
Save007();
return 0;
}
void Save007()
{
bool IsSave = false;
for (int i = 0; i < n; i++)
{
if (!Visited[i] && FirstJump(i))
{
IsSave = DFS(i);
if (IsSave)
break;
}
}
if (IsSave)
printf("Yesn");
else
printf("Non");
}
bool DFS(int V)
{
Visited[V] = true;
bool answer = false;
if (IsSave(V))
return true;
for (int i = 0; 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) >= 50 - d)
|| (abs(P[V].y) >= 50 - 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;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 不要在Spring单元测试中使用 @Transactional注解
- OpenCV DNN模块官方教程(一)加载Caffe模型做图像分类
- Python爬虫之mongodb的聚合操作
- Linux中文输入法-搜狗输入法安装方法
- oracle 数据库问题:"ORA-01922: 必须指定 CASCADE 以删除...",原因及解决办法
- OpenCV DNN模块官方教程(二)YoloV4目标检测实例
- Python爬虫之mongodb的增删改查
- 恕我直言你可能真的不会java第2篇:Java Stream API?
- Python爬虫之mongodb的简单使用
- Java之美-死锁
- 恕我直言你可能真的不会java第4篇:Stream管道流Map操作
- 高工也要补基础,wait,notify,join
- 恕我直言你可能真的不会java第5篇:Stream的状态与并行操作
- 恕我直言你可能真的不会java第3篇:Stream的Filter与谓词逻辑
- 恕我直言你可能真的不会java第1篇:lambda表达式会用了么?