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 "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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/571423.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

commit是直接提交到远程吗 svn_xcode 把项目代码提交到远程SVN服务器

环境 xcode 7 Mac airxcode默认支持GIT源码管理工具&#xff0c;但现在想把代码提交到已有到SVN服务器上&#xff0c;步骤如下&#xff1a;1&#xff0c;在safari中打开svn链接地址&#xff0c;信任证书&#xff0c;输入用户名密码 &#xff0c;登陆成功&#xff0c;可以在浏览…

oracle导入 表 卡住了,oracle数据库怎么导入dmp,只导入数据不导入表结构?

使用方法&#xff1a;Exp parameter_namevalue or Exp parameter_name(value1,value2……)只要输入参数helpy就可以看到所有帮助.EXP常用选项1.FULL&#xff0c;这个用于导出整个数据库&#xff0c;在ROWSN一起使用时&#xff0c;可以导出整个数据库的结构。例如&#xff1a;ex…

【bzoj3991】[SDOI2015]寻宝游戏 树链的并+STL-set

题目描述 给出一棵树&#xff0c;初始每个点都是非必经的。多次改变某个点的必经状态&#xff0c;并询问从任意一个点出发&#xff0c;经过所有必经的点并回到该点的最小路程。 输入 第一行&#xff0c;两个整数N、M&#xff0c;其中M为宝物的变动次数。 接下来的N-1行&#xf…

vue 引入json地图_VUE中通过Echarts引入地图

渲染的方法如下 记得引入echartsimport echarts from echarts-----------------------------------init(dalian){this.$nextTick(()>{var myChart this.$echarts.init(document.getElementById(echartMap));echarts.registerMap(dalian, dalian,{});myChart.setOption({ser…

Django---admin

Django内置admin 1.配置路由 urlpatterns [url(r^admin/, admin.site.urls),] 2.定制admin 在admin.py中只需要讲Mode中的某个类注册&#xff0c;即可在Admin中实现增删改查的功能&#xff0c;如&#xff1a; admin.site.register(models.UserInfo) 但是&#xff0c;这种方式比…

vue 父组件获取接口值传到子组件_vue父组件异步获取数据传给子组件的方法

但是现在问题是父组件的数据是异步获取的&#xff0c;而子组件一开始就会渲染&#xff0c;如果此时没有传入数据&#xff0c;而子组件又要用到数据中的length属性时就会报错&#xff1a;怎么办呢&#xff1f;最简单的办法就是让子组件条件渲染&#xff0c;当有数据的时候才渲染…

python爬取数据需要注意的问题

1 爬取https的网站或是接口的时候&#xff0c;如果是不受信用的SSL证书&#xff0c;会报错&#xff0c;需要添加如下代码&#xff0c;如下代码可以保证当前代码块内所有的请求都自动屏蔽ssl证书问题&#xff1a; import ssl # 这个是爬取https的链接需要的&#xff0c;以及下…

pandas 合并所有列_Python学习:Pandas库+练习资料

pandas包含数据结构和数据处理工具的设计使得在Python中进行数据清洗和分析非常快捷。pandas经常是和NumPy,Scipy以及数据可视化工具matplotlib一起使用的。pandas支持大部分NumPy语言风格的数组计算&#xff0c;但最大的不同在于pandas是用于处理表格型或异质型数据的。而NumP…

oracle 取mac地址,java执行命令,得到Mac地址

public static void main(String[] args) {String os System.getProperty("os.name");System.out.println("操作系统:"os);String address "";if (os ! null && os.startsWith("Windows")) {try {String command "cmd…

solidity 十六进制字符串转十六进制bytes

pragma solidity ^0.4.16;contract Metadata {// 十六进制字符串转换成bytesfunction hexStr2bytes(string data)returns (bytes){uint _ascii_0 48;uint _ascii_A 65;uint _ascii_a 97;bytes memory a bytes(data);uint[] memory b new uint[](a.length);for (uint i 0;…

spring配置主库从库_Spring主从数据库的配置和动态数据源切换原理

原文&#xff1a;https://www.liaoxuefeng.com/article/00151054582348974482c20f7d8431ead5bc32b30354705000在大型应用程序中&#xff0c;配置主从数据库并使用读写分离是常见的设计模式。在Spring应用程序中&#xff0c;要实现读写分离&#xff0c;最好不要对现有代码进行改…

oracle rac实例切换,RAC+单实例DG的切换

RAC单实例DG的切换RAC单实例DG的搭建过程之前切换不成功&#xff0c;和参数设置有关。注意的参数是sid* 之类的&#xff0c;刚搭建好的环境racdbdg是单实例的&#xff0c;是备库&#xff0c;rac节点是主库。搭建完毕&#xff0c;切换了一次&#xff0c;刚好主库是单实例的racdb…

tablueau地图标记圆形_R语言在线地图神器:Leaflet for R包(三) 符号标记

如果还是直接写&#xff0c;会出现错误提示&#xff0c;说找不到经纬度的列像这种情况&#xff0c;就需要进行显式申明了&#xff1a;(顺便换个背景底图)leaflet(dh)%>%addProviderTiles("Esri.WorldStreetMap")%>%setView(116.4,39.9,zoom10)%>%addMarkers…

zabbix自动发现主机并加入组绑定模板

在被监控主机多的情况下&#xff0c;怎样将这些主机加入zabbix server进行监控呢&#xff1f;下面将介绍下zabbix自动发现功能 1、创建自动发现规则 创建“规则名称&#xff0c;配置ip范围及检查方式”&#xff0c;点击“增加”&#xff0c;完成自动发现规则的创建 2、加入组和…

oracle ora 08103,ORA-08103: 对象不再存在

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼[2017-05-17 17:13:22] Function Called in lngGetDataTableWithParametersselect distinct to_char (b.chargeactive_dat, yyyymmdd) as orderdate,to_char(a.recipeno2_int) as recipeno2_chr, b.orderexectype_int as ordertype…

kotlin 用协程做网络请求_中国电信营业厅: 感受 Kotlin 的 quot;加速度quot;

"我们手上是一个很成熟的项目&#xff0c;所以毫无疑问需要保留 Java 代码&#xff0c;目前只会在新开发的页面中使用 Kotlin&#xff0c;并已经感受到了它带来的便利。随着功能的迭代&#xff0c;我们相信更多的功能会转而使用 Kotlin。"—— 付迎鑫&#xff0c;电信…

拖动验证码插件

拖动验证码插件 效果图&#xff1a; 在验证前&#xff0c;提交弹出验证失败&#xff0c;验证后弹出验证成功。 文件结构&#xff1a; css&#xff1a; #drag{ position: relative;background-color: #e8e8e8;width: 300px;height: 34px;line-height: 34px;text-align: center; …

matlab padarray函数零,matlab padarray函数

1padarray功能&#xff1a;填充图像或填充数组。用法&#xff1a;B padarray(A,padsize,padval,direction)A为输入图像&#xff0c;B为填充后的图像&#xff0c;padsize给出了给出了填充的行数和列数&#xff0c;通常用[r c]来表示。padval表示填充方法。它的具体值和描述如下…

如何将已有图片做成透明水印_如何用Photoshop在图片上添加透明水印?

我们经常会在网上看到一些漂亮的图片上有添加各种水印&#xff0c;添加水印可以让图片有一个标记&#xff0c;也可以防止别人盗用你的成果。那么图片上的这些水印是怎么添加的呢&#xff1f;今天&#xff0c;小编就给大家介绍用Photoshop软件来制作图片的透明水印的教程&#x…

[知了堂学习笔记]_网络基础知识_1.OSI参考模型(网络七层协议)

OSI参考模型是国际标准化组织ISO制定的模型&#xff0c;把计算机与计算机之间的通信分成七个互相连接的协议层&#xff0c;如图&#xff1a; 1.1各层功能 1、物理层 最底层是物理层&#xff0c;这一次负责传送比特流&#xff0c;它从第二层数据接收数据帧&#xff0c;并将帧的结…