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
#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 ;
}
最新文章
- 启动Eclipse弹出:Failed to load JavaHL Library 错误框的解决办法
- 怎么解决Android studio导入项目卡死
- 游戏服务器端引擎--DogSE的设计
- 你好,C++(40)7.1 一切指针都是纸老虎:彻底理解指针
- html+javascript实现可拖动弹出层、对话框、可提交
- ios9怎么设置6位密码 ios9设置6位密码图文教程
- HTML5离线应用与客户端存储
- [extjs(1)]MyEclipse2014安装ext4插件Spket
- vultr VPS的购买及搭建ss介绍,支持锐速加速优化
- sql:常用函数
- 设 $y_1(x), y_2(x)$ 是 $y&#39;&#39;+p(x)y&#39;+q(x)y=0$ 的两个解 ($p(x), q(x)$ 连续), 且 $y_1(x_0)=y_2(x_0)=0$, $y_1(x)\not\equiv 0$. 试证: $y_1(x)$, $y_2(x)$ 线性相关.
- Centos 7 64位 minimal 最小化安装的系统中静默安装oracle 11g r2
- MySQL 大数据量分页优化
- 快速开发项目,用到的工具:UI 设置利器 sketch
- js判断类型的四种方法
- scp 的用法
- 【CSS Demo】网站页面变灰
- MySQL程序之mysqldump详解
- bundle install 安装的 gem 提示 cannot load such file
- 【转帖】(一)unity4.6Ugui中文教程文档-------概要