P3958 [NOIP2017 提高组] 奶酪

原题链接

思路

并查集
然后看看是否存在上表面联通的洞与下表面联通的洞位于同一集合

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;
}

posted @   纯粹的  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示