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 <bits/stdc++.h>
using namespace std;
int n,d;
struct node{
int x,y;
int vis;
};
int main()
{
node l[105];
cin>>n>>d;
for(int i =1;i<=n;i++){
int a,b;
cin>>a>>b;
l[i].x = a+50;
l[i].y = b+50;
l[i].vis = 0;
}
vector<node>c;
for(int i = 1;i<=n;i++){
double dis = sqrt( (l[i].x-50) *(l[i].x-50 )+(l[i].y -50)*(l[i].y-50) );
if(dis <= 7.5 + d){
l[i].vis = 1;
c.push_back(l[i]);
}
}
int cnt = c.size();
int ccnt = 0;
while(ccnt < cnt){
for(int i = 1;i<=n;i++){
if(l[i].vis )continue;
for(int j = 0;j<cnt;j++){
double dis = sqrt((l[i].x -c[j].x)*(l[i].x -c[j].x)+(l[i].y -c[j].y)*(l[i].y -c[j].y));
if(dis <= d){
l[i].vis = 1;
c.push_back(l[i]);
}
}
}
ccnt = cnt;
cnt = c.size();
}
int flag = 0;
for(int i = 0;i<cnt;i++){
if( sqrt( (c[i].x-50) *(c[i].x-50 )+(c[i].y -50)*(c[i].y-50) ) + d >= 50){
flag = 1;
break;
}
}
if(flag)cout<<"Yes";
else cout<<"No";
return 0;
}
计算詹姆斯·邦德在鳄鱼湖中逃脱可能性的算法,
这篇文章描述了一个基于电影《活与死》情节的问题,涉及计算间谍詹姆斯·邦德在满是鳄鱼的湖中,利用最大跳跃距离逃脱的算法。输入包括鳄鱼位置和邦德的跳跃能力,输出是否能成功逃脱。
408

被折叠的 条评论
为什么被折叠?



