Saving James Bond - Easy Version

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 (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( 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
 1 #include<stdio.h>
2 int sign = 0;
3 double r = 7.5;
4 int n,d;
5 struct Node{
6 int x;
7 int y;
8 }croc[105];
9
10 int visited[105] = {0};
11
12 void ReadIn(){
13
14 for(int i = 0; i < n ; i++){
15 scanf("%d %d",&croc[i].x,&croc[i].y);
16 }
17 return ;
18 }
19 int isOk(int k){ //判断能否上岸
20 int d1 = 50-croc[k].x < croc[k].x + 50 ?50-croc[k].x:croc[k].x + 50;
21 int d2 = 50-croc[k].y < croc[k].y + 50 ?50-croc[k].y:croc[k].y + 50;
22 int dmin = d1<d2?d1:d2;
23 if(dmin <= d){
24 return 1;
25 }
26 return 0;
27 }
28 int isconnect(int k,int i){ //判断能否跳过去
29 int dq = (croc[k].x-croc[i].x)*(croc[k].x-croc[i].x)+(croc[k].y-croc[i].y)*(croc[k].y-croc[i].y);
30 if(dq <= d*d){
31 return 1;
32 }
33 return 0;
34 }
35
36 void DFS(int k){
37 if(isOk(k)){
38 sign = 1;
39 printf("Yes");
40 return ;
41 }
42 visited[k] = 1;
43 //printf("%d",k);
44 for(int i = 0; i < n;i++){
45 if(isconnect(k,i)&&visited[i]==0){
46 DFS(i);
47 if(sign){
48 break;
49 }
50 }
51 }
52 return ;
53 }
54 int isFirstStep(int i){
55 int dq = croc[i].x*croc[i].x+croc[i].y*croc[i].y;
56 //printf("dq%d=%d\n",i,dq);
57 if(dq <= (d+r)*(d+r)){
58 return 1;
59 }
60 return 0;
61 }
62
63
64
65
66 int main(){
67 scanf("%d %d",&n,&d);
68 if(d+r>=50){
69 printf("Yes");
70 return 0;
71 }
72 ReadIn();
73 for(int i = 0; i <n;i++){
74 if(isFirstStep(i)){
75 DFS(i);
76 }
77 if(sign){
78 break;
79 }
80 }
81 if(sign==0){
82 printf("No");
83 }
84 return 0;
85 }
 

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

  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. 【奇淫巧技】sqlmap绕过过滤的tamper脚本分类汇总

    sqlmap绕过过滤的tamper脚本分类汇总

  2. 【题解】CF1324F

    Question 题目大意:每个点不是黑点就是白点,求以每一个点为根时,选择出一个联通块,使得白点数与黑点数之差最大(白减黑). \(Solution\) 考虑先跑一遍\(dp\). 可以写出一个比较 ...

  3. ansible-playbook通过github拉取部署Lnmp环境

    1. 配置服务器初始化  1.1) 关闭防火墙和selinux 1 [root@test-1 ~]# /bin/systemctl stop firewalld 2 [root@test-1 ~]# ...

  4. Java安全之Javassist动态编程

    Java安全之Javassist动态编程 0x00 前言 在调试CC2链前先来填补知识盲区,先来了解一下Javassist具体的作用.在CC2链会用到Javassist以及PriorityQueue来 ...

  5. Linux系统安装JDK1.8

    2020最新Linux系统发行版ContOS7演示安装JDK. 为防止操作权限不足,建议切换root用户,当然如果你对Linux命令熟悉,能够自主完成权限更新操作,可以不考虑此推荐. 更多命令学习推荐 ...

  6. 1T数据快速排序!十种经典排序算法总结

    1 冒泡排序 每次循环都比较前后两个元素的大小,如果前者大于后者,则将两者进行交换.这样做会将每次循环中最大的元素替换到末尾,逐渐形成有序集合.将每次循环中的最大元素逐渐由队首转移到队尾的过程形似&q ...

  7. Linux发行版教你如何选 给入门者的选择通法

    Linux的发行版何止琳琅满目,简直是乱入你眼. 本篇将介绍选择发行版的经验和通用法则,主要会从PC角度去谈. 更新于2020年,初次发布于2017年 选择发行版需考虑哪些因素 选择发行版时需要考虑的 ...

  8. 解决/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory报错 (转)

    解决/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory报错 念淅 2020-01-03 15:02:25 3793 收 ...

  9. linux(centos8):禁用selinux(临时关闭/永久关闭)

    一,selinux的用途 1,什么是selinux SELinux:即安全增强型 Linux(Security-Enhanced Linux) 它是一个 Linux 内核模块,也是 Linux 的一个 ...

  10. centos8安装及配置nfs4

    一,用rpm检查是否有nfs-utils的包已安装 [root@localhost liuhongdi]# rpm -qa | grep nfs-utils nfs-utils-2.3.3-26.el ...