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 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 (≤100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x,y) 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<iostream>
 2 #include<math.h>
 3 #include<vector>
 4 using namespace std;
 5 #define MaxN 101
 6 int flag=0;
 7 vector<int> visited(MaxN,0);
 8 struct node{
 9 int x;
10 int y;
11 };
12 struct Gnode{
13 int N;
14 int D;
15 node G[MaxN];
16 };
17 using Graph=Gnode*;
18 Graph buildGraph(){
19 int N,D,x,y;
20 cin>>N>>D;
21 Graph gra=new Gnode();
22 gra->N=N; gra->D=D;
23 gra->G[0].x=0; gra->G[0].y=0;
24 for(int i=1;i<=gra->N;i++){
25 cin>>x>>y;
26 gra->G[i].x=x; gra->G[i].y=y;
27 }
28 return gra;
29 }
30 double distance(node n1,node n2)
31 {
32 return sqrt((n1.x-n2.x)*(n1.x-n2.x)+(n1.y-n2.y)*(n1.y-n2.y));
33 }
34 int finish(Graph gra,int v){
35 if(gra->G[v].x>=50-gra->D)
36 {flag=1;return 1;}
37 if(gra->G[v].x<=-50+gra->D)
38 {flag=1;return 1;}
39 if(gra->G[v].y>=50-gra->D)
40 {flag=1;return 1;}
41 if(gra->G[v].y<=-50+gra->D)
42 {flag=1;return 1;}
43 return 0;
44 }
45 void DFS(Graph gra,int v){
46 visited[v]=1;
47 if(finish(gra,v))
48     return;
49 for(int i=1;i<=gra->N;i++)
50 if(visited[i]!=1&&distance(gra->G[i],gra->G[v])<=gra->D)
51 DFS(gra,i);
52 }
53 void Givenanswer(Graph gra){
54 int v;
55 if(gra->D>=50)
56 flag=1;
57 for(v=1;v<=gra->N;v++){
58 if(flag==0){  //cout<<distance(gra->G[v],gra->G[0])-7.5<<endl;
59 if(visited[v]!=1&&distance(gra->G[v],gra->G[0])-15<=gra->D)
60 {  DFS(gra,v);}
61 }
62
63 }
64 if(flag==1) cout<<"Yes"<<endl;
65 else cout<<"No"<<endl;
66 }
67 int main()
68 {
69 Graph gra=buildGraph();
70 Givenanswer(gra);
71 return 0;
72 }

View Code

转载于:https://www.cnblogs.com/A-Little-Nut/p/8056106.html

Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33相关推荐

  1. PTA 06-图2 Saving James Bond - Easy Version (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/672 5-10 Saving James Bond - Easy Version   ( ...

  2. The Wide and Deep Learning Model(译文+Tensorlfow源码解析) 原创 2017年11月03日 22:14:47 标签: 深度学习 / 谷歌 / tensorf

    The Wide and Deep Learning Model(译文+Tensorlfow源码解析) 原创 2017年11月03日 22:14:47 标签: 深度学习 / 谷歌 / tensorfl ...

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

  4. 六、图(上):Saving James Bond - Easy Version

    目录 题目描述 代码 注意事项 题目描述 This time let us consider the situation in the movie "Live and Let Die&quo ...

  5. Saving James Bond - Easy Version

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  6. 中国大学MOOC-陈越、何钦铭-数据结构 Saving James Bond - Easy Version

    题目描述: This time let us consider the situation in the movie "Live and Let Die" in which Jam ...

  7. 算法 图2 Saving James Bond - Easy Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案汇总 题目:This time let us consider the situation in the movie & ...

  8. 最新Win7 +Python3.6.0(Anaconda3-4.3.21)+Tensorflow的安装与配置(不用切换python3.5) 原创 2017年09月23日 15:14:58 标签:pyt

    最新Win7 +Python3.6.0(Anaconda3-4.3.21)+Tensorflow的安装与配置(不用切换python3.5) 一.首先进入Anaconda官网下载  https://ww ...

  9. 2017年11月23日学习笔记_用python解决杨辉三角函数,以及理解

    今天学习了廖雪峰老师的python教程,学到杨辉三角函数的时候很迷茫, 他的基本格式如下: [1],[1, 1],[1, 2, 1],[1, 3, 3, 1],[1, 4, 6, 4, 1],[1, ...

最新文章

  1. 免费公开课 | 基于定制数据流技术的AI计算加速
  2. RabbitMQ(四):RabbitMQ与Spring Boot简单整合 快速尝鲜版
  3. 不能执行已经释放掉的Script代码!(已解决)
  4. 14nm芯片技术突破 中国集电关键装备实现从无到有
  5. 用IntelliJ IDEA 配置安卓(Android)开发环境(一条龙服务,新手进!)
  6. 那些开发《虚拟光驱》的人们
  7. python 颜色_Python可视化|matplotlib07自带颜色条Colormap(三)
  8. P2421 A-B数对(增强版)
  9. CTO视点 | 思科打造业界首个基于意图的开放性网络平台,释放无限机遇
  10. 如何制作媲美memz的炫酷特效恶搞程序
  11. 最全面的PLC学习网站
  12. 设计模式(4):生成器模式(Builder)
  13. 培训班出来的程序员能找到工作吗?
  14. sd卡无法完成格式化解决办法
  15. Android moudle库使用aar的方法
  16. 标志logo设计/欣赏
  17. 神经网络(4)---神经网络是如何帮助我们学习复杂的nonlinear hypotheses
  18. python训练自己中文语料库_Python nltk载入自己的中文语料库的两种方法 for Windows7...
  19. 常量与变量有哪些区别
  20. 研究生平均年薪26.5万!本科生20万!南京大学软件学院19年就这么高!

热门文章

  1. matlab如何导入多文本数据,将文本文件中的混合数据导入表
  2. 表级锁的mysql读写_Mysql的表级锁
  3. python 2x可以打么_Python打基础一定要吃透这68个内置函数
  4. c++ 访问控制与封装
  5. mysql_install_db is deprecated_MySQL5.7源码安装问题汇总
  6. nginx php 防止跨站,Nginx下多网站单独php-fpm进程目录权限防跨站
  7. 基于Java SSM springboot+VUE+redis实现的前后端分类版网上商城项目
  8. 大学计算机基础知识判断题,大学计算机基础学习知识判断题.doc
  9. exif linux php扩展_LNMP环境为PHP添加exif扩展
  10. C++ 重载new和delete运算符