连接: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; }
原文地址:https://www.cnblogs.com/fengyuzhicheng/p/9193790.html
时间: 2024-10-03 08:08:00