#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int f[1001],start[1001],end[1001],n,t,num1,num2;
double h,r;
struct nl{
double x,y,z;
};
int find(int x)
{
if(x!=f[x])
{
f[x]=find(f[x]);
}
return f[x];
}
nl a[1001];
bool flag;
double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}
int main()
{
//freopen("cheese.in","r",stdin);
//freopen("cheese.out","w",stdout);
scanf("%d",&t);
while(t--)
{
num1=0;num2=0;
scanf("%d%lf%lf",&n,&h,&r);
for(int i=1;i<=n;i++)
{
f[i]=i;
}
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z);
if(r+a[i].z>=h)
{
num2++;
end[num2]=i;
}
if(a[i].z-r<=0)
{
num1++;
start[num1]=i;
}
for(int k=1;k<=i;k++)
{
if(dis(a[k].x,a[k].y,a[k].z,a[i].x,a[i].y,a[i].z)<=2*r)
{
int k1=find(i),k2=find(k);
if(f[k1]>f[k2])
{
f[k2]=k1;
}else
{
f[k1]=k2;
}
}
}
}
flag=0;
for(int i=1;i<=num1;i++)
{
for(int j=1;j<=num2;j++)
{
if(find(start[i])==find(end[j]))
{
flag=1;
break;
}
}
if(flag)
{
break;
}
}
if(flag)
{
cout<<"Yes"<<endl;
}else
{
cout<<"No"<<endl;
}
}
return 0;
}
2.dfs
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct cz{
double x,y,z;
};
double h,r;
int n,t;
bool vis[1001],flag;
cz a[1001];
double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{
return sqrt((pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2)));
}
bool pd(cz a,cz b)
{
return a.z<b.z;
}
void dfs(int now)
{
if(a[now].z+r>=h)
{
flag=1;
return;
}
vis[now]=1;
for(int i=1;i<=n;i++)
{
if(flag)//剪枝,已经找到,直接退
{
return;
}
if(!vis[i]&&dis(a[i].x,a[i].y,a[i].z,a[now].x,a[now].y,a[now].z)<=2*r)
{
dfs(i);
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
memset(vis,0,sizeof(vis));
scanf("%d%lf%lf",&n,&h,&r);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z);
}
sort(a+1,a+1+n,pd);
flag=0;
for(int i=1;i<=n;i++)
{
if(a[i].z-r<=0)
{
dfs(i);
}
}
if(flag)
{
cout<<"Yes"<<endl;
}else
{
cout<<"No"<<endl;
}
}
return 0;
}