06-图2 Saving James Bond - Easy Version
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.
假设该湖泊是100乘100平方的湖泊。假设湖的中心在(0,0),而东北角在(50,50)。中心岛是一个以(0,0)为中心的圆盘,直径为15。在湖中的不同位置上有许多鳄鱼。给定每条鳄鱼的坐标和詹姆斯可以跳跃的距离,您必须告诉他是否可以逃脱。
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.
每个输入文件包含一个测试用例。每种情况都从包含两个正整数N(≤100)(鳄鱼的数量)和D(James可以跳跃的最大距离)的行开始。然后紧接着N行,每行都包含鳄鱼的(x,y)位置。请注意,没有两个鳄鱼停留在同一位置。
Output Specification:
For each test case, print in a line “Yes” if James can escape, or “No” if not.
对于每个测试用例,如果James可以逃脱,则在行“是”上打印,否则,请在“否”上打印。
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<bits/stdc++.h>
using namespace std;
struct Node{
int x,y;
}node[101];
int n,m;
bool visited[101]={false};
bool result=false;
double Distance(int a,int b){
double aa;
aa=sqrt(pow(node[a].x-node[b].x,2)+pow(node[a].y-node[b].y,2));
return aa;
}
bool Run(int v){
if(node[v].x>=50-m||node[v].y>=50-m||node[v].x<=m-50||node[v].y<=m-50){
return true;
}
return false;
}
bool DFS(struct Node node[],int v,bool visit[]){
visited[v]=true;
if(Run(v)){
result= true;
}
else{
for(int i=1;i<=n;i++){
if(!visited[i]&&Distance(v,i)<=m){
result =DFS(node,i,visited);
}
}
}
return result;
}
int main(){
cin>>n>>m;
node[0].x=0;
node[0].y=0;
for(int i=1;i<=n;i++){
cin>>node[i].x>>node[i].y;
}
visited[0]=true;
for(int i=1;i<=n;i++){
if(Distance(0,i)<=(m+7.5)){
result=DFS(node,i,visited);
if(result){
cout<<"Yes";
break;
}
}
}
if(!result){
cout<<"No";
}
return 0;
}