Mn Zn 求助,30 Pts
查看原帖
Mn Zn 求助,30 Pts
407417
HerikoDeltana楼主2021/5/6 19:38

代码如下

#include <bits/stdc++.h>
#define Heriko return
#define Deltana 0
#define S signed
#define U unsigned
#define LL long long
#define R register
#define I inline
#define D double
#define LD long double
#define mst(a,b) memset(a,b,sizeof(a))
#define ON std::ios::sync_with_stdio(false)
using namespace std;
I void fr(LL &x)
{
	LL f=1;char c=getchar();
	x=0;
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
}
void fw(LL x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) fw(x/10);
	putchar('0'+x%10);
}

LL n,h,r,f[1005],n1[100005],n2[100005],t;
LL find(LL x)
{
	if(x!=f[x]) f[x]=find(f[x]);
	Heriko f[x];
}
LL dt(LL sx,LL sy,LL sz,LL gx,LL gy,LL gz)
{
	Heriko ((sx-gx)*(sx-gx)+(sy-gy)*(sy-gy)+(sz-gz)*(sz-gz));
}
struct hole
{
	LL x,y,z;
} a[100005];
S main()
{
	fr(t);
	while(t--)
	{
		fr(n);fr(h);fr(r);
		n1[0]=n2[0]=0;
		for(R LL i=1;i<=n;i++) f[i]=i;
		for(R LL i=1;i<=n;i++)
		{
			fr(a[i].x);fr(a[i].y);fr(a[i].z);
			if(a[i].z+r>=h) n1[0]++,n1[n1[0]]=i;
			if(a[i].z-r<=0) n2[0]++,n2[n2[0]]=i;
			for(R LL j=1;j<=i;j++)
			{
				if ((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)>(4*r*r)) continue;
				if(dt(a[i].x,a[i].y,a[i].z,a[j].x,a[j].y,a[i].z)<=4*r*r) 
				{
					LL a1=find(i);
                    LL a2=find(j);
                    if (a1!=a2) f[a1]=a2;
				}
			}
		}
		bool b=false;
		for(R LL i=1;i<=n1[0];i++)
		{
			for(R LL j=1;j<=n2[0];j++)
			{
				if(find(n1[i])==find(n2[j]))
				{
					b=true;
					break;
				}
			}
			if(b) break;
		}
		if(b) putchar('Y'),putchar('e'),putchar('s'),putchar('\n');
		else putchar('N'),putchar('o'),putchar('\n');
	}
	Heriko Deltana;
}

2021/5/6 19:38
加载中...