思路
并查集
然后看看是否存在上表面联通的洞与下表面联通的洞位于同一集合
code
#include<bits/stdc++.h>
using namespace std;
double n,h,r;
int fa[1005];
vector<int> up,down;
struct
{
double x,y,z;
}hole[1005];
double dis(int i,int j)
{
return pow(hole[i].x-hole[j].x,2)+pow(hole[i].y-hole[j].y,2)+pow(hole[i].z-hole[j].z,2);
}
int finds(int now)
{
return fa[now]=((now==fa[now])?now:finds(fa[now]));
}
int check()
{
for(auto i: up)
for(auto j: down)
if(finds(i)==finds(j))return 1;
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>h>>r;
for(int i=1;i<=n;i++)
{
fa[i]=i;
cin>>hole[i].x>>hole[i].y>>hole[i].z;
if(hole[i].z+r>=h)up.push_back(i);
if(hole[i].z-r<=0)down.push_back(i);
}
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(dis(i,j)<=r*4*r) fa[finds(i)]=finds(fa[j]);//合并集合
if(check())puts("Yes");
else puts("No");
up.clear();
down.clear();
}
return 0;
}
标签:NOIP2017,return,int,奶酪,fa,P3958,hole,now,finds
From: https://www.cnblogs.com/pure4knowledge/p/18016609