poj Wireless Network
来源:互联网 发布:仿真实训软件 编辑:程序博客网 时间:2024/05/22 10:33
AC情况:
大致思路:这题看到就往并查集上靠了,就是判断距离那块感觉有点费时间,不过AC了,之前WA一次,查了半天发现是FAIL输成了FALL,,难受。。。
#include<iostream>using namespace std;int x[1001];int y[1001];int r[1001] = {0};int par[1001];int ran[1001];void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; ran[i] = 0; }}int find(int x) { int j, r; r = x; while (par[r] != r)r = par[r]; while (par[x] != r) { j = par[x]; par[x] = r; x = j; } return r;}void unite(int x, int y) { x=find(x); y = find(y); if (x != y) { ran[x] < ran[y] ? par[x] = y : par[y] = x; if (ran[x] == ran[y])ran[y]++; }}int main() { int N, D,i,op1,op2; char c; cin >> N >> D; init(N); for (i = 0; i < N; i++) cin >> x[i] >> y[i]; while (cin >> c) { if (c == 'O') { cin >> op1; op1--; r[op1] = 1; for (i = 0; i < N; i++) if (r[i]&&find(op1)!=find(i)) if (D*D >= (x[i] - x[op1])*(x[i] - x[op1]) + (y[i] - y[op1])*(y[i] - y[op1])) { unite(op1, i); } }if (c == 'S') { cin >> op1 >> op2; op1--; op2--; if (find(op1) == find(op2)) cout << "SUCCESS"<<endl; else cout << "FAIL"<<endl; } } return 0;}
阅读全文
0 0
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ-2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236 - Wireless Network
- poj 2236 Wireless Network
- POJ 2236 Wireless Network
- poj 2236 wireless network
- POJ--2236--Wireless Network
- POJ-2236-Wireless Network
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- C#中 virtual 和 abstract 区别
- Oracle12154解决办法
- Retrofit2使用
- RH124-第十节-文件打包压缩,以及rsync传输
- 取文件路径时,当路径中有空格时,返回的是encode字符串的路径,这样导致找不到相对应的路径
- poj Wireless Network
- 1016~1017 函数的使用2-3(回文数判断)
- T
- 排序库函数sort()和qsort()
- eventbus发送消息刷新上一页listview 消息接收不到及返回上一页时数组角标越界
- 2017年22日 华为网络技术工程师面试
- 数据库——(4)数据类型
- 计算机图形学
- jsp地址栏传参乱码解决方法