7-10 拯救007 (25 分)

在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)

设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为圆心、直径15米的圆。给定池中分布的鳄鱼的坐标、以及007一次能跳跃的最大距离,你需要告诉他是否有可能逃出生天。

输入格式:

首先第一行给出两个正整数:鳄鱼数量 N(≤100)和007一次能跳跃的最大距离 D。随后 N 行,每行给出一条鳄鱼的 (x,y) 坐标。注意:不会有两条鳄鱼待在同一个点上。

输出格式:

如果007有可能逃脱,就在一行中输出"Yes",否则输出"No"。

输入样例 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

输出样例 1:

Yes

输入样例 2:

4 13
-12 12
12 12
-12 -12
12 -12

输出样例 2:

No

#include<bits/stdc++.h>
using namespace std;
#define maxn 110
struct E{
	int x;
	int y;
	int pre;
}temp;
queue<E>q,q1;
int ma[maxn][maxn][2]={0};//ma[i][j][0]=1表示可走,ma[i][j][1]=0表示没走过
int main(){
	int n,m;
	cin>>n>>m;
	for( int i=0; i<n ; i++ ){
		int v1,v2;
		cin>>v1>>v2;
		v1+=50;v2+=50;//将横纵坐标加50;
		ma[v1][v2][0]=1;
	}
	for( int i=0; i<maxn; i++ ){//从中心岛走
		for( int j=0; j<maxn; j++ ){
			if(ma[i][j][0]==1){
				if(sqrt(pow(50-i,2)+pow(50-j,2))<=7.5+m){
					temp.x=i;temp.y=j;temp.pre=1;
					q.push(temp);
					ma[i][j][1]=-1;
				}
			}
		}
	}
	while(!q.empty()){
		temp=q.front();
		q.pop();
		q1.push(temp);
		for( int i=0; i<maxn; i++ ){//从鳄鱼头上走
			for( int j=0; j<maxn; j++ ){
				if(ma[i][j][0]==1&&ma[i][j][1]==0){
					if(sqrt(pow(temp.x-i,2)+pow(temp.y-j,2))<=m){
						E ans;
						ans.x=i;ans.y=j;ans.pre=temp.pre+1;
						q.push(ans);
						ma[i][j][1]=-1;
					}
				}
			}
		}
	}
	while(!q1.empty()){//能否逃离
		temp=q1.front();
		if(temp.x-0<=m||100-temp.x<=m||temp.y-0<=m||100-temp.y<=m){
			cout<<"Yes\n"; return 0;
		} 
		q1.pop();
	}
	cout<<"No\n";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43323172/article/details/88884766