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
 #include<iostream>
#include<math.h>
#include<vector>
using namespace std;
#define MaxN 101
int flag=;
vector<int> visited(MaxN,);
struct node{
int x;
int y;
};
struct Gnode{
int N;
int D;
node G[MaxN];
};
using Graph=Gnode*;
Graph buildGraph(){
int N,D,x,y;
cin>>N>>D;
Graph gra=new Gnode();
gra->N=N; gra->D=D;
gra->G[].x=; gra->G[].y=;
for(int i=;i<=gra->N;i++){
cin>>x>>y;
gra->G[i].x=x; gra->G[i].y=y;
}
return gra;
}
double distance(node n1,node n2)
{
return sqrt((n1.x-n2.x)*(n1.x-n2.x)+(n1.y-n2.y)*(n1.y-n2.y));
}
int finish(Graph gra,int v){
if(gra->G[v].x>=-gra->D)
{flag=;return ;}
if(gra->G[v].x<=-+gra->D)
{flag=;return ;}
if(gra->G[v].y>=-gra->D)
{flag=;return ;}
if(gra->G[v].y<=-+gra->D)
{flag=;return ;}
return ;
}
void DFS(Graph gra,int v){
visited[v]=;
if(finish(gra,v))
return;
for(int i=;i<=gra->N;i++)
if(visited[i]!=&&distance(gra->G[i],gra->G[v])<=gra->D)
DFS(gra,i);
}
void Givenanswer(Graph gra){
int v;
if(gra->D>=)
flag=;
for(v=;v<=gra->N;v++){
if(flag==){ //cout<<distance(gra->G[v],gra->G[0])-7.5<<endl;
if(visited[v]!=&&distance(gra->G[v],gra->G[])-<=gra->D)
{ DFS(gra,v);}
} }
if(flag==) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int main()
{
Graph gra=buildGraph();
Givenanswer(gra);
return ;
}

Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33的更多相关文章

  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. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

  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. 洛谷 P1589 泥泞路

    题目描述 暴雨过后,FJ的农场到镇上的公路上有一些泥泞路,他有若干块长度为L的木板可以铺在这些泥泞路上,问他至少需要多少块木板,才能把所有的泥泞路覆盖住. 输入输出格式 输入格式: 第一行为正整数n( ...

  2. iOS UITableView reloadData 刷新结束后执行后续操作

    如果在reloadData后需要立即获取tableview的cell.高度,或者需要滚动tableview. 如果直接在reloadData后执行代码是有可能出问题的,比如indexPath为nil等 ...

  3. 在HTML页面中实时获取新消息的方法 “JavaScript中的setInterval用法”

    JavaScript中的setInterval用法(资料来源:博主---八神吻你   ) setInterval动作的作用是在播放动画的时,每隔一定时间就调用函数,方法或对象.可以使用本动作更新来自数 ...

  4. 在脚本中输入密码执行sudo,可关机等。

    如下,makexxx.sh make update-api make echo "password" | sudo -S shutdown -h now

  5. 浅析 Spark Shuffle 内存使用

    在使用 Spark 进行计算时,我们经常会碰到作业 (Job) Out Of Memory(OOM) 的情况,而且很大一部分情况是发生在 Shuffle 阶段.那么在 Spark Shuffle 中具 ...

  6. SecureCRT中vi或vim编辑器显示中文乱码问题

    vi ~/.vimrc  //新建文件 syntax on set showmode set autowrite set number set encoding=utf-8 fileencodings ...

  7. Smart SVN的使用

    最近项目使用了SVN,为管理代码起到了很好的作用!但是,对于很多初步使用着,还是非常不容易! 公司使用的是Smart SVN 客户端. Smart SVN 这个工具总体还是挺不错的! 在代码的提交和获 ...

  8. tween.js下面的轮播(饿了么点餐的那种效果)

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  9. TensorFlow中屏蔽warning的方法

    问题 使用sudo pip3 install tensorflow安装完CPU版tensorflow后,运行简单的测试程序,出现如下警告: I tensorflow/core/platform/cpu ...

  10. Web前端基础怎么学? JavaScript、html、css知识架构图

    以前开发者只要掌握 HTML.CSS.JavaScript 三驾马车就能胜任一份前端的工作了.而现在除了普通的编码以外,还要考虑如何性能优化,如何跨端.跨平台实现功能,尤其是 AI.5G 技术的来临, ...