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. Python基本数据类型详细介绍

    Python提供的基本数据类型主要有:布尔类型.整型.浮点型.字符串.列表.元组.集合.字典等等 1.空(None)表示该值是一个空对象,空值是Python里一个特殊的值,用None表示.None不能 ...

  2. 在程序开发中,++i 与 i++的区别在哪里?

    哈哈哈! 从大学开始又忘了...蜜汁问题哈 参考来源:https://www.zhihu.com/question/19811087/answer/80210083 i++ 与 ++i 的主要区别有两 ...

  3. 硬盘安装Linux

    准备材料:U盘.Linux镜像.UltraISO 1.下载安装UltraISO, 2.打开系统镜像 打开后我们就可以在左边侧栏看到镜像的内容 3.插入U盘,点击:启动->写入光盘映像->选 ...

  4. 正式班D7

    2020.10.13星期二 正式班D7 一.上节课复习 Linux发展 批处理系统 多道技术 分时操作系统 multics->Unix->minix->Linux(如Redhat.c ...

  5. Python:MySQL数据库环境相关问题

    系统环境 Ubuntu 16.04.2 LTS mysql Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using  EditLine wrapper P ...

  6. protoc-c 阅读笔记

    以前和山哥做过类似的,最近想起来,抽空又看了下 protoc-c. 山哥做的报文流向: rpc -> lydtree -> motree -> struct 涉及的细节很多 1) l ...

  7. 多测师讲解html _段落标签002_高级讲师肖sir

    <html> <head> <meta charset="UTF-8"> <title>段落标签</title> < ...

  8. Rust之路(2)——数据类型 上篇

    [未经书面同意,严禁转载] -- 2020-10-13 -- Rust是系统编程语言.什么意思呢?其主要领域是编写贴近操作系统的软件,文件操作.办公工具.网络系统,日常用的各种客户端.浏览器.记事本. ...

  9. 微信小程序tabbar不显示2019.04.06

    app.json中pages的第一项必须在tabBar中,且这一项需要在pages的list中(与顺序无关)否则无法显示tabBar app.json中pages数组中第一项(首页),必须在tabBa ...

  10. day16 Pyhton学习

    1.range(起始位置) range(终止位置) range(起始,终止位置) range(起始,终止,步长) 2.next(迭代器) 是内置函数 __next__是迭代器的方法 g.__next_ ...