POJ 2236 Wireless Network(并查集)
来源:互联网 发布:易知投资工资 编辑:程序博客网 时间:2024/06/01 10:07
题目链接:Wireless Network
每个点用一个标记表示修没修好,然后每次和距离小于d的进行并查集即可
代码:
#include <stdio.h>#include <string.h>#include <math.h>const int N = 1005;int n, parent[N];double d;struct Point { int x, y, vis;} p[N];double dis(Point a, Point b) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));}void init() { memset(p, 0, sizeof(p)); for (int i = 1; i <= n; i++)parent[i] = i;}int find(int x) { if (x == parent[x])return x; return parent[x] = find(parent[x]);}int main() { while (~scanf("%d%lf", &n, &d)) {init();for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y);char q[2]; int a, b;while (~scanf("%s", q)) { if (q[0] == 'O') {scanf("%d", &a);p[a].vis = 1;for (int i = 1; i <= n; i++) { if (p[i].vis && (dis(p[i], p[a]) < d || fabs(dis(p[i], p[a]) - d) < 1e-9)) {int pa = find(i);int pb = find(a);if (pa != pb) parent[pa] = pb; }} } else {scanf("%d%d", &a, &b);int pa = find(a);int pb = find(b);if (pa == pb) { printf("SUCCESS\n");}else { printf("FAIL\n");} }} } 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 2236 Wireless Network(并查集)
- poj 2236 Wireless Network 并查集
- POJ 2236--Wireless Network【并查集】
- poj 2236 Wireless Network 并查集
- S3C2440上MMC/SD卡驱动实例开发讲解(一)
- X-47B已执行首次夜间飞行
- S3C2440上MMC/SD卡驱动实例开发讲解(二)
- 爱立信面试,面试官给我出的 C 算法问题
- 棋盘问题
- POJ 2236 Wireless Network(并查集)
- 遍历集合时出现的异常Exception in thread "main" java.util.ConcurrentModificationException
- 1059 搬寝室
- HDU 1005 Number Sequence
- php文件上传
- A New Year Gift
- 供参考的 php 学习路线
- MySQL索引背后的数据结构及算法原理
- MGTemplateEngine 模版引擎简单使用