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. matlab中卷积convolution与filter用法

    转自:https://blog.csdn.net/dkcgx/article/details/46652021 转自:https://blog.csdn.net/Reborn_Lee/article/ ...

  2. sysfs是什么??

    来源:https://blog.csdn.net/qq_36412526/article/details/83751520 第一次接触:sysfs, 这里记录过程: 原文:Documenttation ...

  3. juc包:使用 juc 包下的显式 Lock 实现线程间通信

    一.前置知识 线程间通信三要素: 多线程+判断+操作+通知+资源类. 上面的五个要素,其他三个要素就是普通的多线程程序问题,那么通信就需要线程间的互相通知,往往伴随着何时通信的判断逻辑. 在 java ...

  4. 你知道CPU结构也会影响Redis性能吗?

    啦啦啦,我是卖身不卖艺的二哈,ε=(´ο`*)))唉错啦(我是开车的二哈),我又来了,铁子们一起开车呀! 今天来分析下CPU结构对Redis性能会有影响吗? 在进行Redis性能分析的时候,通常我们会 ...

  5. nuget使用经验:复杂依赖关系下的包版本问题

    背景 之前同事问到过1个关于nuget包被多层引用后,最终生效的版本的问题.当时通过在项目中重新安装了一次nuget包解决了. 现在来重新复盘一下当时的场景,顺便把这种场景下nuget处理逻辑分享给大 ...

  6. php正则偷电影

    1.是将电影网站弄到自己的phpstudy下面,然后进行获取电影的一些数据,然后将其存到数据库,不要获取别人网站的数据,不然会导致网站的崩溃.

  7. 许嵩新歌《放肆》发布 && 递归 + Stream+Lambda相遇成树

    一.<放肆>如约而至 今早5:00在迷迷糊糊中醒来,打开手机一看,许嵩又发新歌了,名字叫做<放肆>,澎湃的旋律,依旧古典高雅的用词,这个大男孩,已经不像12年那时候发些伤感非主 ...

  8. 网页添加 Live2D 看板娘

        我是先参考别人的[点击跳转]博客来做的.不过我发现网上很多人都没有把一些细节写出来,用了别人那里下载的文件后里面的一些跳转链接就跳到他们的页面了.所以我这里写一写如何修改这些跳转链接吧. 1. ...

  9. 【应用服务 App Service】当使用EntityFrameWorkCore访问Sql Server数据库时,在Azure App Service会出现Cannot create a DbSet for ** because this type is not included in the model for the context的错误

    问题情形 使用EF Core访问数据库,在本地运行正常,发布到App Service后,偶尔出现了Cannot create a DbSet for ** because this type is n ...

  10. CAP-微服务间通信实践

    微服务间通信常见的两种方式 由于微服务架构慢慢被更多人使用后,迎面而来的问题是如何做好微服务间通信的方案.我们先分析下目前最常用的两种服务间通信方案. gRPC(rpc远程调用) gRPC-微服务间通 ...