码迷,mamicode.com
首页 > 其他好文 > 详细

[Luogu] 奶酪

时间:2018-05-03 11:38:44      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:--   stream   fine   并查集   ons   ref   space   node   iostream   

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
*/

 

[Luogu] 奶酪

标签:--   stream   fine   并查集   ons   ref   space   node   iostream   

原文地址:https://www.cnblogs.com/shandongs1/p/8984482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!