POJ.2236 Wireless Network (并查集)
来源:互联网 发布:数控车床编程实例 简单 编辑:程序博客网 时间:2024/05/17 13:41
POJ.2236 Wireless Network (并查集)
题意分析
查询点直接O(n)搞就行了,我想的是画个内切正方形,然后二分,或者kdtree。10sec其实不用了。
代码总览
#include <cstdio>#include <cstring>#include <algorithm>#define nmax 1200using namespace std;struct point{ int x, y; bool isok;}p[nmax];int father[nmax];int rnk[nmax];int n,d;void makeset(int x){ father[x] = x; rnk[x] = 0;}int findset(int x){ int r = x,temp; while(father[r] != r) r = father[r]; while(x != r){ temp = father[x]; father[x] = r; x = temp; } return r;}void unionset(int x, int y){ x = findset(x); y = findset(y); if(x == y) return; else{ if(rnk[x] > rnk[y]) father[y] = x; else{ father[x] = y; if(rnk[x] == rnk[y]) rnk[x]++; } }}int main(){// freopen("in.txt","r",stdin); scanf("%d %d",&n,&d); for(int i = 1;i<=n;++i) scanf("%d %d",&p[i].x,&p[i].y),makeset(i); char op; while(scanf(" %c",&op) != EOF){ int a,b; if(op == 'O'){ scanf("%d",&a); p[a].isok = true; int temp = 0; for(int i = 1;i<=n;++i){ if(i == a) continue; temp = (p[i].x - p[a].x) * (p[i].x - p[a].x) + (p[i].y - p[a].y) *(p[i].y - p[a].y); if(temp <= d * d && p[i].isok) unionset(a,i); } }else{ scanf("%d %d",&a,&b); a = findset(a); b = findset(b); if(a == b) 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 并查集
- python 练习一
- ubuntu环境下vlcj报错:A fatal error has been detected #C [libc.so.6+0x121024] _IO_file_underflow+0x64
- 关于WebService 的用法demo 总结
- python-opencv3 kmeans图像分类
- python-opencv3 kmeans图像分类
- POJ.2236 Wireless Network (并查集)
- Ubuntu环境下vjudge系统搭建
- 流控制语句-break与label联用
- 尚不清晰或者未学习的东西
- iOS学习笔记-090.彩票05——购彩大厅2_自定义蒙版、popMenu、UIView分类抽取
- 常用参考表对照表
- 作业
- 试密码(20)
- 日期累加