bfs
不想多说,就bfs爆搜,写起来挺麻烦的,不需要方向数组,不需要设置偏移量
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
struct loc{
double x,y,z;
}a[N];
int st[N];
int n,h,r;
queue<loc> q;
double dist(loc l1,loc l2)
{
double dx=l1.x-l2.x, dy=l1.y-l2.y, dz=l1.z-l2.z;
return sqrt((dx*dx)+(dy*dy)+(dz*dz));
}
int bfs(void)
{
while(!q.empty())
{
loc u=q.front();
if(u.z+r>=h)return true;
q.pop();
for(int i=1;i<=n;i++)
{
if(st[i]==0&&dist(u,a[i])<=2*r)
{
st[i]=1;
q.push(a[i]);
if(a[i].z+r>=h)
{
return true;
}
}
}
}
return false;
}
int main()
{
int t;
cin>>t;
while(t--)
{
memset(st, 0, sizeof st);
while(!q.empty())q.pop();
cin>>n>>h>>r;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>a[i].z;
if(a[i].z<=r)
{
q.push(a[i]);
st[i]=1;
}
}
if(bfs())cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}