直接代码
#include<bits/stdc++.h>
using namespace std;
int T,n;
double h,r;
bool fnd=0,vis[1002];
struct node{
double x,y,z;
bool operator<(const node &cpr)const{return z<cpr.z;}
} p[1002];
double dist(node p1,node p2){
return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+(p2.z-p1.z)*(p2.z-p1.z));
}
void dfs(node now,int k){
if(now.z+r>=h){fnd=true;return;}
vis[k]=true;
for(int i=1;i<=n;i++){
if(fnd) return;
if(!vis[i]&&dist(now,p[i])<=r*2) dfs(p[i],i);
} vis[k]=0;
return;
}
int main(){
scanf("%d",&T);
while(T--){
memset(vis,0,sizeof(vis));
memset(p,0,sizeof(p));
fnd=0;
scanf("%d%lf%lf",&n,&h,&r);
for(int j=1;j<=n;j++){scanf("%lf%lf%lf",&p[j].x,&p[j].y,&p[j].z);}
sort(p+1,p+n+1);
for(int i=1;i<=n;i++)
if(p[i].z-r<=0) dfs(p[i],i);
if(fnd) printf("Yes");
else printf("No");
}
return 0;
}