找bug

//7-14 拯救007 (25 分)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
struct node{
	int x;
	int y;
}p[105]; 
bool book[105];
int n,k;
queue<node> q;
int flag=0;
void bfs(){
	while(!q.empty()){
		node tmp=q.front();
		q.pop();
		for(int i=1;i<=n;i++){
			if(book[i]) continue;
			book[i]=1;
			if((p[i].x-tmp.x)*(p[i].x-tmp.x)+(p[i].y-tmp.y)*(p[i].y-tmp.y)<=k*k){
				if(p[i].x<=-50+k||p[i].x>=50-k||p[i].y>=50-k||p[i].y<=-50+k){
					flag=1;
					return ;
				}
				else{
					q.push(p[i]);
				}
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&k);
	memset(book,0,sizeof(book));
	for(int i=1;i<=n;i++){
		scanf("%d%d",&p[i].x,&p[i].y);
		int d=p[i].x*p[i].x+p[i].y*p[i].y;
		if(d<=(k+15)*(k+15)&&d>15*15){
			q.push(p[i]);
			book[i]=1;
		} 
	}
	if(q.empty()){
		cout<<"No"<<endl;
	}
	else{
		bfs();
		if(flag) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42710001/article/details/85092547
bug