zoukankan      html  css  js  c++  java
  • [Gym-102346A] 偷偷偷 并查集处理图(坐标)

    https://vjudge.net/problem/Gym-102346A

    题意:判断监控器的范围能不能阻断左下角和右上角。

    分析:利用并查集处理图,能连接起来的监控器合并起来,然后在最后标记每个集合能否连接到左下、右上、左右、上下的边界形成阻断。

    注意: 每个集合可以用 find( x ) 到的祖先下标标记。

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5+5;
    const int mod=998244353;
    int pre[maxn];
    
    struct node{
        int x,y,l;
    }s[maxn];
    
    bool check(node a,node b){
        return ( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) <= (a.l+b.l)*(a.l+b.l));
    }
    
    int find(int x){
        if(x!=pre[x]){
            pre[x] = find(pre[x]);
        }
        return pre[x];
    }
    
    void Union(int x,int y){
        int rx=find(x),ry=find(y);
        if(find(x) != find(y)){
            pre[rx] = ry;
        }
    }
    
    struct Node{
        int x,y,a,b;
    }ans[maxn];
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n,m,k;
        cin>>m>>n>>k;
        for(int i=1; i<=k; i++){
            cin>>s[i].x>>s[i].y>>s[i].l;
        }
        for(int i=1; i<=k; i++){
            pre[i] = i;
        }
        for(int i=1; i<=k-1; i++){
            for(int j=i+1; j<=k; j++){
                if( check(s[i],s[j]) ){
                    Union(i,j);
                }
            }
        }
    
        for(int i=1; i<=k; i++){
            if(s[i].x<=s[i].l){
                ans[ find(i) ].x = 1;
            }
            if(s[i].y<=s[i].l){
                ans[ find(i) ].y = 1;
            }
            if(m-s[i].x<=s[i].l){
                ans[ find(i) ].a = 1;
            }
            if(n-s[i].y<=s[i].l){
                ans[find(i)].b = 1;
            }
        }
        bool ok=0;
        for(int i=1; i<=k; i++){
            if(ans[i].x==1 && ans[i].y==1){
                ok=1;
            }
            if(ans[i].a==1 && ans[i].b==1){
                ok=1;
            }
            if(ans[i].x==1 && ans[i].a==1){
                ok=1;
            }
            if(ans[i].y==1 && ans[i].b==1){
                ok=1;
            }
            //cout<<ans[i].x<<" "<<ans[i].y<<endl;
        }
        if(ok) cout<<"N"<<endl;
        else cout<<"S"<<endl;
    }
  • 相关阅读:
    etcd基本操作
    使用docker配置etcd集群
    etcd启用https服务
    etcd3集群管理
    Opengl绘制我们的小屋(一)球体,立方体绘制
    OpenGL 用三角形模拟生成球面
    PDFSharp生成PDF.
    OpenXml操作Word的一些操作总结.无word组件生成word.
    F# 图形数学基础。
    SQL Server (MSSQLSERVER) 服务因 2148081668 服务性错误而停止。
  • 原文地址:https://www.cnblogs.com/-Zzz-/p/11784893.html
Copyright © 2011-2022 走看看