【hdu】 Wireless Network (并查集)
来源:互联网 发布:office for mac 免费 编辑:程序博客网 时间:2024/06/05 07:30
Wireless Network
Time Limit : 20000/10000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 8 Accepted Submission(s) : 6
Problem Description
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.
In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.
In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.
Input
The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats:
1. "O p" (1 <= p <= N), which means repairing computer p.
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.
The input will not exceed 300000 lines.
1. "O p" (1 <= p <= N), which means repairing computer p.
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.
The input will not exceed 300000 lines.
Output
For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.
Sample Input
4 10 10 20 30 4O 1O 2O 4S 1 4O 3S 1 4
Sample Output
FAILSUCCESS
#include<cstdio>#include<cstring>#define MAX 1010bool flag[MAX];int f[MAX],w[MAX][2];void init(){ for(int i=0;i<MAX;i++){f[i]=i;}} int find(int x){ if(f[x]==x)return x; f[x]=find(f[x]); return f[x];}void Union(int x,int y){ int p=find(x); int q=find(y); if(p!=q) f[p]=q;}int main(){ int n,m,i,a,b; char s[2]; scanf("%d%d",&n,&m);memset(flag,false,sizeof(flag));init(); for(i=1;i<=n;i++) scanf("%d%d",&w[i][0],&w[i][1]); while(scanf("%s",s)!=EOF) { if(s[0]=='O') { scanf("%d",&a); if(flag[a])continue; else { flag[a]=true; for(i=1;i<=n;i++) { if(flag[i]&&i!=a) { if(((w[a][0]-w[i][0])*(w[a][0]-w[i][0])+(w[a][1]-w[i][1])*(w[a][1]-w[i][1]))<=m*m) { Union(a,i);// printf("%d %d\n",a,i); } } } } } else { scanf("%d%d",&a,&b); if(find(a)==find(b)){ puts("SUCCESS");} else puts("FAIL"); } } return 0; }
- 【hdu】 Wireless Network (并查集)
- HDU-2236-Wireless Network(并查集)
- POJ2236 Wireless Network(并查集)
- POJ2236 Wireless Network(并查集)
- poj2236 Wireless Network(并查集)
- POJ Wireless Network (并查集)
- POJ2236 Wireless Network(并查集)
- Wireless Network (并查集)
- POJ2366 Wireless Network(并查集)
- Wireless Network (并查集)
- Wireless Network(并查集)
- POJ2236 Wireless Network(并查集)
- 【并查集】Wireless Network
- 并查集----Wireless Network
- Wireless Network 并查集
- Wireless Network 并查集
- Wireless Network --并查集
- Wireless Network(并查集(裸))
- Matlab任意正六边形随机撒点 实现-----------通信仿真必备
- Training4:字符串训练 练习
- 配置VIM语法高亮及自动缩进
- android01 -- activity
- redhat Linux系统 chmod授权命令
- 【hdu】 Wireless Network (并查集)
- 黑马程序员_学习日记76_801ASP.NET(ORM框架CRUD、EF ModelFirst编程方式、延迟加载机制)
- 用闪回恢复delete,insert,update表(学习手记1)
- sql语句
- LDD3源码分析之hello.c与Makefile模板
- 第一次求职---流水账
- 在节点树中获取文档的下一个元素节点
- LDD3源码分析之调试技术
- 《职业规划》课程笔记