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 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
#include<cstdio>
#include<cmath>
#include<cstdlib>
const double ISLAND_RADIUS = 15.0 / ;
const double SQUARE_SIZE = 100.0;
const int maxn = ; typedef struct Point{
double x,y;
}Position; Position P[maxn];
int n;
double d;
bool vis[maxn]; void save007();
bool FirstJump(int v);
bool DFS(int v);
bool isSave(int v);
bool Jump(int v1,int v2); 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++){
vis[i] = false;
}
save007();
return ;
} void save007(){
bool isVist = false;
for(int i = ; i < n; i++){
if(!vis[i] && FirstJump(i)){
isVist = DFS(i);
if(isVist) break;
}
}
if(isVist) printf("Yes\n");
else printf("No\n");
} bool FirstJump(int v){
return sqrt(P[v].x * P[v].x + P[v].y * P[v].y) <= d + ISLAND_RADIUS;
} bool DFS(int v){
bool answer = false;
vis[v] = true;
if(isSave(v)) return true;
for(int i = ; i < n; i++){
if(!vis[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 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 (25 分)的更多相关文章
- 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 ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 05-图2. Saving James Bond - Easy Version (25)
1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- 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 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 ...
- 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 ...
- 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 ...
随机推荐
- 【270】IDL处理GeoTIFF数据
参考:将原GeoTIFF数据的投影坐标信息赋值到新创建的文件上 pro tiff_projection ;启动ENVI e = ENVI(/HEADLESS) ;打开文件 file = 'D:\01- ...
- activity状态保存的bundl对象存放位置的思考
我们知道,当activity被异常终止时,可以把一些信息保存到bundle对象中,在下次启动时恢复. 那么,这个bundle对象是保存在哪里的呢? 这种状态保存的方法针对的是activity而不是进程 ...
- LINUX关闭防火墙、开放特定端口等常用操作
1. 重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2. 即时生效,重启后失效: 开启:service iptables s ...
- SQl Server 函数篇 数学函数,字符串函数,转换函数,时间日期函数
数据库中的函数和c#中的函数很相似 按顺序来, 这里价格特别的 print 可以再消息栏里打印东西 数学函数 ceiling() 取上限 不在乎小数点后面有多大,直接忽略 floor() ...
- 在Ubuntu里安装Mysql5.7.23
准备在Linux里安装Mysql,安装过程中遇到很多问题,这里记录下我成功安装的过程. 操作系统:Ubuntu 18.04 数据库:Mysql 5.7.23 安装步骤: 1.下载一个apt,下载mys ...
- 高性能MySQL笔记-第5章Indexing for High Performance-003索引的作用
一. 1. 1). Indexes reduce the amount of data the server has to examine.2). Indexes help the server av ...
- 1、awk打开多个文件的方法
转载:http://www.cnblogs.com/Berryxiong/p/6209324.html 1.当awk读取的文件只有两个的时候,比较常用的有三种方法(1)awk 'NR==FNR{... ...
- Entity Framework Tutorial Basics(6):Model Browser
Model Browser: We have created our first Entity Data Model for School database in the previous secti ...
- 转/keystore和truststore的区别
keytool是java自带的工具用于产生密钥 keystore可以看成一个放key的库,key就是公钥,私钥,数字签名等组成的一个信息. truststore是放信任的证书的一个store. 那他们 ...
- HDU 2102 A计划 (BFS或DFS)
题意:中文题. 析:是一个简单的搜索,BFS 和 DFS都可行, 主要是这个题有一个坑点,那就是如果有一层是#,另一个层是#或者*,都是过不去的,就可以直接跳过, 剩下的就是一个简单的搜索,只不过是两 ...