POJ2236-Wireless Network
来源:互联网 发布:pytorch与tensorflow 编辑:程序博客网 时间:2024/05/12 05:41
以电脑之间的连通关系建立并查集,连接符合条件的电脑并检查连通性即可。
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;typedef pair<int, int> P;const int MAXN = 1001;int par[MAXN+5];int high[MAXN+5];bool status[MAXN+5];P com[MAXN+5];int dis(P a, P b){ return pow(a.first-b.first, 2) + pow(a.second-b.second, 2);}void init(int n){ for (int i = 1; i <= n; i++) { par[i] = i; high[i] = 0; }}int find(int x){ if (x == par[x]) { return x; } return par[x] = find(par[x]);}void unite(int x, int y){ x = find(x); y = find(y); if (high[x] < high[y]) { par[x] = y; } else { par[y] = x; if (high[x] == high[y]) { high[x]++; } }}bool connect(int x, int y){ return find(x) == find(y);}int main(){ int n, d; scanf("%d%d", &n, &d); for (int i = 1; i <= n; i++) { scanf("%d%d", &com[i].first, &com[i].second); } getchar(); init(n); int ch; while ((ch = getchar()) != EOF) { int x, y; if (ch == 'O') { scanf("%d", &x); status[x] = true; for (int i = 1; i <= n; i++) { if (status[i] == true && dis(com[x], com[i]) <= pow(d, 2)) { if (i == x) { continue; } unite(x, i); } } } else { scanf("%d%d", &x, &y); if (connect(x, y)) { puts("SUCCESS"); } else puts("FAIL"); } getchar(); } return 0;}
0 0
- POJ2236 Wireless Network
- poj2236 - Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236---Wireless Network
- POJ2236--Wireless Network
- poj2236 Wireless Network
- poj2236 Wireless Network
- POJ2236-Wireless Network
- POJ2236(Wireless Network)
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- poj2236 Wireless Network
- poj2236 Wireless Network
- POJ2236——Wireless Network
- Handler消息机制 源码解读
- 算法导论之动态规划:钢条切割
- 枚举类型的使用方法
- 设置页面最小height
- 两个Activity之间利用Intent方法传递数据
- POJ2236-Wireless Network
- 1.redis-简介--数据类型
- 编写高质量的CSS代码,规范建议
- Android线程池详解
- IdeaSpace安装
- 灵码root项目读源码。
- 华为OJ——求int型数据在内存中存储时1的个数
- CSS margin 属性
- Android高级控件----AdapterView与Adapter