初始化,半径精度都考虑了,难道是板子打错了?
by seventeen @ 2018-11-05 13:23:03
```cpp
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
long long a[2002],b[2002],c[2002];
int father[2002];
long long juli(long long x1,long long x2,long long y1,long long y2,long long z1,long long z2)
{return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);}
int find(int a)
{
while(a!=father[a])
{
a=father[a];
father[a]=father[father[a]];
}
return a;
}
void Union(int c,int d)
{
while(father[d]!=c)
{d=father[d];
father[d]=c;
}
}
int main()
{
int T,shang,xia,cnt,cmt,s,qi[2002],zhong[2002],j,k,i;
long long n,h,r;
cin>>T;
for(i=1;i<=T;i++)
{
shang=0;
xia=0;
cnt=1;
cmt=1;
s=0;
memset(father,0,2002) ;
memset(qi,0,2002);
memset(zhong,0,2002);
cin>>n>>h>>r;
for(j=1;j<=n;j++)
{cin>>a[j]>>b[j]>>c[j];
father[j]=j;
if(c[j]<=r) {xia++; qi[cnt++]=j;}
if(c[j]+r>=h) {shang++; zhong[cmt++]=j;}
}
for(j=1;j<=n;j++)
for(k=j+1;k<=n;k++)
if(juli(a[j],a[k],b[j],b[k],c[j],c[k])<=4*r*r&&find(j)!=find(k)&&j!=k) Union(j,k);
for(j=1;j<=shang;j++)
{if(s==1) break;
for(k=1;k<=xia;k++)
if(find(zhong[j])==find(qi[k])) {cout<<"Yes"<<endl;s=1;break;}
}
if(s==0) cout<<"No"<<endl;
}
// system("pause");
return 0;
}
``` system("pause");
return 0;
}
by seventeen @ 2018-11-05 13:25:11
~~为什么要写高精~~
by Jameswood @ 2018-11-05 13:28:34
~~我眼瞎~~
by Jameswood @ 2018-11-05 13:28:57
距离试试用double类型求@[seventeen](/space/show?uid=56754)
by Jameswood @ 2018-11-05 13:29:46
@[Jameswood](/space/show?uid=52428) 一开始用的long double
by seventeen @ 2018-11-05 20:03:59
好吧睿智并查集炸了
by seventeen @ 2018-11-05 20:33:51