zoukankan      html  css  js  c++  java
  • 源哥每日一题第十九弹 poj 2236 还是冰茶集

    连接:http://poj.org/problem?id=2236

    题意:有一堆坏电脑,和两种操作:O表示修好这台电脑,S 询问两台电脑是否联通。主要是判电脑是否联通:两台电脑间距离小于d就是联通的。

    题解:emmm……直接写啊

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    int n;
    long long d;
    int pre[1005];
    int jud[1005];
    struct coor
    {
        long long x,y;
    }p[1005];
    
    int find(int x) {
        int r = x;
        while(pre[r]!=r) r = pre[r];
        int i = x,j;
        while(i!=r) {
            j = pre[i];
            pre[i] = r;
            i = j;
        }
        return r;
    }
    
    int main(int argc, char const *argv[]) {
        
        int n,d;
        cin >> n >> d;
        for (int i = 1; i <= n; i++) {     
            cin >> p[i].x >> p[i].y;
            pre[i] = i;
            jud[i] = 0;
        }
        char s;
        int x,y;
        while(cin >> s) {
    
            if(s =='S') {
                cin >> x >> y;
                if(find(x) == find(y)) {
                    puts("SUCCESS");
                } else { 
                    puts("FAIL");
                }
            } else {
                cin >> x;
                for (int i = 1; i <= n; i++) {
                    if(jud[i] && (p[x].x-p[i].x)*(p[x].x-p[i].x)+(p[x].y-p[i].y)*(p[x].y-p[i].y) <=d*d){
                        pre[find(x)] = find(i);
                    }
                }
                jud[x] = 1;
            }
        }
        return 0;
    }
  • 相关阅读:
    Arctic Network POJ
    Journey CodeForces
    Free Goodies UVA
    MU Puzzle HDU
    Balance POJ
    1sting 大数 递推
    最大报销额 暴力。。
    洛谷P2826 LJJ的数学课
    2018年12月29日
    2018年12月28日
  • 原文地址:https://www.cnblogs.com/fengyuzhicheng/p/9193790.html
Copyright © 2011-2022 走看看