ACM-模拟/搜索 Saving James Bond - Easy Version（25 分）深搜

#include<bits/stdc++.h>
using namespace std;
struct node{
double x,y;
}fish[105];
/*bool cmp(node a,node b){
return a.x*a.x+a.y*a.y<=b.x*b.x+b.y*b.y;
} */
bool vis[105];
int n;
double d;
bool end(int x){//完成逃生
return (fish[x].x+d>=50||fish[x].x-d<=-50||fish[x].y+d>=50||fish[x].y-d<=-50);
}
bool judge(int a,int b){//可以进行跳跃
return ((fish[a].x-fish[b].x)*(fish[a].x-fish[b].x)+(fish[a].y-fish[b].y)*(fish[a].y-fish[b].y)<=d*d);
}
bool dfs(int x){
vis[x]=true;
if(end(x)){
return true;
}
else for(int i=0;i<n;i++){
if(!vis[i]&&judge(x,i)){
if(dfs(i))return true;//往下探索，再往上传递
}
}
return false;
}
int main(){
ios::sync_with_stdio(false);
//freopen("1.txt","r",stdin);
cin>>n>>d;
int first;
for(int i=0;i<n;i++){
cin>>fish[i].x>>fish[i].y;
vis[i]=false;
}
//sort(fish,fish+n,cmp);
int flag=0;
for(int i=0;i<n;i++){
if((fish[i].x*fish[i].x+fish[i].y*fish[i].y)<=((7.5+d)*(7.5+d))&&!vis[i]){
if(!vis[i]&&dfs(i)){
printf("Yes\n");
flag=1;
break;
}
}
}
if(!flag)cout<<"No\n";
return 0;
}