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. 《Java从入门到失业》第五章:继承与多态(5.1-5.7):继承

    5.继承与多态 5.1为什么要继承 最近我儿子迷上了一款吃鸡游戏<香肠派对>,无奈给他买了许多玩具枪,我数了下,有一把狙击枪AWM,一把步枪AK47,一把重机枪加特林(Gatling).假 ...

  2. 多线程循环打印数组 -- Java笔记

    问题描述: 现有多个长度相同的数组,现要求使用多线程将数组内的数交替打印. 如: int[] ai = {1,2,3,4,5,6,7}; String[] ac = {"A",&q ...

  3. CLP(FD)有限域上的约束逻辑式编程

    译自http://www.pathwayslms.com/swipltuts/clpfd/clpfd.html#_simple_constraints,SWI-Prolog官网所推荐的进阶教程.目前还 ...

  4. 008 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 02 Java 中的关键字

    008 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 02 Java 中的关键字 关键字 关键字就是一些有特殊意义的词 之前学习的程序中涉及到的关键字 Java中 ...

  5. TCP/IP 寻址

    原文:TCP/IP 寻址 第一节:TCP/IP 简介 第二节:TCP/IP 寻址 第三节:TCP/IP 协议 第四节:TCP/IP 邮件 TCP/IP 使用 32 个比特(bit)或者 4 个 0 到 ...

  6. GAN网络之入门教程(四)之基于DCGAN动漫头像生成

    目录 使用前准备 数据集 定义参数 构建网络 构建G网络 构建D网络 构建GAN网络 关于GAN的小trick 训练 总结 参考 这一篇博客以代码为主,主要是来介绍如果使用keras构建一个DCGAN ...

  7. 草率了,又一个Maven打包的问题

    经常遇到 Maven 相关的问题,这是之前的文章: 这个 Maven 依赖的问题,你敢说你没遇到过:https://mp.weixin.qq.com/s/SzBbDtyRUrk_7LH8SUbGXQ ...

  8. pytest文档53-命令行实时输出错误信息(pytest-instafail)

    前言 pytest 运行全部用例的时候,在控制台会先显示用例的运行结果(.或F), 用例全部运行完成后最后把报错信息全部一起抛出到控制台. 这样我们每次都需要等用例运行结束,才知道为什么报错,不方便实 ...

  9. MySQL锁详细讲解

    本文章向大家介绍MySQL锁详细讲解,包括数据库锁基本知识.表锁.表读锁.表写锁.行锁.MVCC.事务的隔离级别.悲观锁.乐观锁.间隙锁GAP.死锁等等,需要的朋友可以参考一下   锁的相关知识又跟存 ...

  10. 【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)

    注意:在对Service Fabric的节点做操作之前,请务必确认是否是种子节点(Seed Node)且当前节点的数量是否与SF的持久层要求的数量一致. 可靠性级别是 Service Fabric 群 ...