poj-2236-Wireless Network
来源:互联网 发布:淘宝代理需要多少钱 编辑:程序博客网 时间:2024/05/18 04:00
并查集简单题 题意表面是1000*20000的数量级 其实最坏只需要(1+1000)*1000/2次合并就行了。。。
#include<cstdio>int n,d;char order[10];struct node{ int x,y;}a[2000];int fa[2000],am[2000],st[2000];void init() { for(int i=1;i<=n;i++) { fa[i] = -1; am[i] = 0; }}int toGetFarther(int i){ while(!(fa[i]==i||fa[i]==-1)) i = fa[i]; return i;}void unon(int x,int y){ int fax = toGetFarther(x),fay = toGetFarther(y); if(fax!=fay) { if(am[fax]>am[fay]) { fa[fay] = fax; am[fax]+=am[fay]; } else { fa[fax] = fay; am[fay] += am[fax]; } }}int main(){ scanf("%d%d",&n,&d); int l1 = 0; init(); for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y); while(scanf("%s",order)!=EOF) { if(order[0]=='O') { int to; scanf("%d",&to); if(fa[to]!=-1)continue;//如果已经修过就没必要再修了。。。 else{ fa[to] = to; am[to] = 1; for(int i=0;i<l1;i++) if((a[st[i]].x-a[to].x)*(a[st[i]].x-a[to].x)+(a[st[i]].y-a[to].y)*(a[st[i]].y-a[to].y)<=d*d) unon(st[i],to); st[l1] = to; l1++; } } else { int st,en; scanf("%d%d",&st,&en); int stf = toGetFarther(st); int enf = toGetFarther(en); if(stf==enf&&stf!=-1)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 2236Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- 关于IList、IQueryable、IEnumerable与Func、Expression的关系2-详解
- Redis快速入门
- wdk驱动开发的特点
- 图片编辑canvas
- 46.BOOL / bool / Boolean / NSCFBoolean
- poj-2236-Wireless Network
- 既然选择了前方,便不顾风雨兼程。
- Codeforces 645A Amity Assessment【八数码】
- JS代码预解析原理
- java 不保留移动文件renameTo,递归遍历子文件夹
- shell--2--变量
- 多线程之NSThread、NSOperation及GCD
- Android常用控件——Dialog之AlertDialog和ProgressDialog
- scala学习第一天