zoukankan      html  css  js  c++  java
  • [Luogu] 奶酪

    https://www.luogu.org/problemnew/show/P3958

    连边bfs / 并查集

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    const int N = 1010;
    
    #define gc getchar()
    
    struct Node{
        double x, y, z;
    }E[N];
    
    int n;
    double h, r;
    int T;
    int f[N];
    
    inline int read(){
        int x = 0; char  c = gc;
        while(c < '0' || c > '9') c = gc;
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
        return x;
    }
    
    int getf(int x){
        return f[x] == x ? x : f[x] = getf(f[x]);
    }
    
    inline bool calc_dis(int x, int y){
        double X1 = E[x].x, Y1 = E[x].y, Z1 = E[x].z;
        double X2 = E[y].x, Y2 = E[y].y, Z2 = E[y].z;
        double dis = sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * ((Y1 - Y2)) + (Z1 - Z2) * (Z1 - Z2));
        return dis <= r * 2 ? 1 : 0;
    }
    
    inline bool dis_0(int x){
        if(abs(E[x].z - 0) <= r) return 1;
        return 0;
    }
    
    inline bool dis_h(int x){
        if(abs(E[x].z - h) <= r) return 1;
        return 0;
    }
    
    int main()
    {
        T = read();
        while(T --){
            n = read();
            scanf("%lf%lf", &h, &r);
            for(int i = 1; i <= n; i ++) f[i] = i;
            for(int i = 1; i <= n; i ++) scanf("%lf%lf%lf", &E[i].x, &E[i].y, &E[i].z);
            for(int i = 1; i <= n; i ++){
                for(int j = 1; j <= n; j ++){
                    if(i != j && calc_dis(i, j)){
                        f[getf(i)] = f[getf(j)];
                    }
                }
            }
            bool flag = 1;
            for(int i = 1; i <= n && flag; i ++){
                for(int j = 1; j <= n && flag; j ++){
                    if(dis_0(i) && dis_h(j) && getf(i) == getf(j)){
                        puts("Yes");
                        flag = 0;
                    }
                }
            }
            if(flag) puts("No");
        }
        return 0;
    }
    /*
    1
    2 5 1
    0 0 1
    0 0 4
    */
  • 相关阅读:
    占位 CP
    占位 LR
    占位 DL
    占位 SC
    Your name ?
    占位 RK
    Gson 关于SpringMVC和json格式问题
    JDBC
    Outlook2016 2019修改默认存储路径文件夹
    Windows Server 2016 任务管理器没有了远程控制 远程桌面,能够控制其它远程用户的会话
  • 原文地址:https://www.cnblogs.com/shandongs1/p/8984482.html
Copyright © 2011-2022 走看看