本文主要是介绍05-2. Saving James Bond - Easy Version (25),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
05-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 12Sample Output 1:
YesSample Input 2:
4 13 -12 12 12 12 -12 -12 12 -12Sample Output 2:
No
提交代码
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define lson rt<<1,l,MID
#define rson rt<<1|1,MID+1,r
//#define lson root<<1
//#define rson root<<1|1
#define MID ((l+r)>>1)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=105;
const int base=1000;
const int inf=999999;
const double eps=1e-5;
struct node
{double x,y;//坐标的X,Yint num;//坐标的标号 便于标记
} p[maxn];//自定义图的节点 存储图bool vis[maxn];//访问标记
double d,n;
int first=1;//第一次是在中心 半径为15的岛上 所以特殊处理
double dis(double x,double y,double xx,double yy)
{if(first){return d+15-sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));first=0;}else return d-sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));}
int ok=1;//第一次是在中心 半径为15的岛上 所以特殊处理
bool pan(node s)
{if(ok){ok=0;if(fabs(s.x-50)<=d+15||fabs(s.x+50)<=d+15||fabs(s.y-50)<=d+15||(s.y+50)<=d+15)return true;}else if(fabs(s.x-50)<=d||fabs(s.x+50)<=d||fabs(s.y-50)<=d||(s.y+50)<=d)return true;return false;
}
int dfs(node s)
{if(pan(s)){return 1;}if(!vis[s.num]){vis[s.num]=true;for(int i=1; i<=n; i++){if(!vis[p[i].num]&&dis(p[i].x,p[i].y,s.x,s.y)>=0){if(dfs(p[i])==1)return 1;}}}return 0;
}int main()
{int m,i,j,k,t;cin>>n>>d;for(i=1; i<=n; i++){cin>>p[i].x>>p[i].y;p[i].num=i;}node s;s.x=s.y=s.num=0;if(dfs(s))puts("Yes");elseputs("No");return 0;
}
这篇关于05-2. Saving James Bond - Easy Version (25)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!