Saving James Bond
来源:互联网 发布:如何更改电脑mac地址 编辑:程序博客网 时间:2024/06/05 14:54
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 2025 -15-25 288 4929 15-35 -25 2827 -29-8 -28-20 -35-25 -20-13 29-30 15-35 4012 12
Sample Output 1:
Yes
Sample Input 2:
4 13-12 1212 12-12 -1212 -12
Sample Output 2:
No
#include<vector>
using namespace std;
#define MaxN 101
int flag=0;
vector<int> visited(MaxN,0);
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[0].x=0; gra->G[0].y=0;
for(int i=1;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>=50-gra->D)
{flag=1;return 1;}
if(gra->G[v].x<=-50+gra->D)
{flag=1;return 1;}
if(gra->G[v].y>=50-gra->D)
{flag=1;return 1;}
if(gra->G[v].y<=-50+gra->D)
{flag=1;return 1;}
return 0;
}
void DFS(Graph gra,int v){
visited[v]=1;
if(finish(gra,v))
return;
for(int i=1;i<=gra->N;i++)
if(visited[i]!=1&&distance(gra->G[i],gra->G[v])<=gra->D)
DFS(gra,i);
}
void Givenanswer(Graph gra){
int v;
if(gra->D>=50)
flag=1;
for(v=1;v<=gra->N;v++){
if(flag==0){ //cout<<distance(gra->G[v],gra->G[0])-7.5<<endl;
if(visited[v]!=1&&distance(gra->G[v],gra->G[0])-15<=gra->D)
{ DFS(gra,v);}
}
}
if(flag==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int main()
{
Graph gra=buildGraph();
Givenanswer(gra);
return 0;
}
- hdu1245 Saving James Bond
- Saving James Bond HDU
- Saving James Bond
- Saving James Bond
- Saving James Bond
- HDOJ 1245 Saving James Bond
- hdu 1245 Saving James Bond
- HDU 1245 Saving James Bond
- Saving James Bond+迪杰斯特拉算法
- HDU1245:Saving James Bond(Floyd)
- HDU 1245 Saving James Bond
- HDU1245:Saving James Bond(Floyd)
- Saving James Bond - Easy Version
- Saving James Bond - Hard Version
- Saving James Bond - Easy Version
- HDU-1245-Saving James Bond
- Saving James Bond - Easy Version
- 5-10 Saving James Bond
- 使用Tensorflow物体识别API抠出视频中的猪
- Win10或Win8下ObjectARX2015 Wizard向导创建项目失败解决方法
- 自学笔记:一个简单的神经网络,机器学习数字图片,可以显示错误的数字的图片
- 欢迎使用CSDN-markdown编辑器
- @ModelAttribute
- Saving James Bond
- 【java多线程编程核心技术】6.单例模式与多线程-笔记总结
- 状态压缩·一 hiho一下第 8 周
- 用户操作(添加、删除、敏感词、排序、查询)
- AngularJS月
- SharePreference
- Angular框架机构
- 订单发货
- Mac OS X下Adware/malware 的简单手动排除方法