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
    */
  • 相关阅读:
    Hard Rock
    Codeforces Round #416 (Div. 2) B. Vladik and Complicated Book
    codeforces 793B. Igor and his way to work
    codeforces 1B Spreadsheets
    HDU 1069 Monkey and Banana
    codeforces 2B The least round way
    【机器学习】 通俗说拟合
    python-八皇后问题
    python-核心知识思维导图
    python-@property 属性
  • 原文地址:https://www.cnblogs.com/shandongs1/p/8984482.html
Copyright © 2011-2022 走看看