PAT Saving James Bond - Easy Version
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的更多相关文章
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- NodeJS二进制合并
Node.js 批量文件合并code cnblogs @ Orcim 本 文主要介绍使用 Node 进行 ACB 序列文件(Atom CueSheet Binary,编译 AtomCueSheet ...
- CISCO交换机STP实验(生成树协议)
目录 一.前言:生成树协议(STP) 二.CISCO交换机STP命令汇总 三.运用STP搭建简单拓扑 四.实战:STP综合实验 五.结语 一.前言:生成树协议(STP) 计算机网络中,我们为了减少网络 ...
- Python 为什么不支持 switch 语句?
本文出自"Python为什么"系列,请查看全部文章 在这篇文章里,我们会聊一聊为什么 Python 决定不支持 switch 语句. 为什么想要聊这个话题呢? 主要是因为 swit ...
- Spring的BeanFactory是什么?
什么是BeanFactory? 提到Spring,总是让人第一时间想起IOC容器,而IOC容器的顶层核心接口就是我们的BeanFactory,如果能够理解BeanFactory的体系结构想必能让我们对 ...
- 项目使用eslint
今天eslint版本更新了,然后昂,有些奇奇怪怪的错误提示了,然后想,这我得 1.配置一个保存时根据eslint规则自动修复 2.欸,之前编码遇到未使用的变量都会有标记黄线,我很好定位,这会怎么没了 ...
- day60 Pyhton 框架Django 03
day61 内容回顾 1.安装 1. 命令行: pip install django==1.11.18 pip install django==1.11.18 -i 源 2. pycharm sett ...
- Jenkins集成appium自动化测试(Windows篇)
一,引入问题 自动化测试脚本绝大部分用于回归测试,这就需要制定执行策略,如每天.代码更新后.项目上线前定时执行,才能达到最好的效果,这时就需要进行Jenkins集成. 不像web UI自动化测试可以使 ...
- centos8安装lvs
一,配置ip转发 [root@localhost sysctl.d]# sysctl -a | grep ip_forward net.ipv4.ip_forward = 1 说明:如果net.ipv ...
- Dubbo系列之 (七)网络层那些事(2)
辅助链接 Dubbo系列之 (一)SPI扩展 Dubbo系列之 (二)Registry注册中心-注册(1) Dubbo系列之 (三)Registry注册中心-注册(2) Dubbo系列之 (四)服务订 ...
- 边界层吞吸技术(BLI)
气流在机体表面前进时,由于受到摩擦,其速度会不断降低,从而会产生湍流甚至气流分离,而流动分离又会造成大量紊流.涡,使升力大量损失,同时也会造成阻力急剧增加.边界层吞吸技术就是一种对附面层气流" ...