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. Educational Codeforces Round 20 B

    Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...

  2. 浅谈Java中static作用--转

    static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...

  3. UIBarButtonItem系统默认风格形状

    typedef NS_ENUM(NSInteger, UIBarButtonSystemItem) { UIBarButtonSystemItemDone, UIBarButtonSystemItem ...

  4. 130 Surrounded Regions 被围绕的区域

    给定一个二维的矩阵,包含 'X' 和 'O'(字母 O), 找到所有被 'X' 围绕的区域.并将区域里所有 'O'用 'X' 填充.例如,X X X XX O O XX X O XX O X X运行你 ...

  5. C#基础学习3

    运算符,表达式!

  6. spoj GCJ1C09C Bribe the Prisoners

    题目链接: http://www.spoj.com/problems/GCJ1C09C/ 题意: In a kingdom there are prison cells (numbered 1 to  ...

  7. cordova安装方法

    安装cordova之前需要先安装node.js和npm 然后在命令行运行:npm install -g cordova即可安装到最新版本的cordova 如果要安装指定版本,命令为:npm insta ...

  8. wkWebView 的一些问题

    导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView 拥有60fps滚动刷 ...

  9. 移除sql数据所有链接用户

    use master;   go   declare @temp nvarchar(20)   declare myCurse cursor   for   select spid   from sy ...

  10. 设置QtreeWidget水平滚动条

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7552603.html //设置treewidget水平滚动条 ui.treeWidget->header ...