POJ---2236-Wireless Network(并查集)
来源:互联网 发布:手机搞怪视频软件 编辑:程序博客网 时间:2024/06/05 11:46
Wireless Network
Time Limit: 10000MS Memory Limit: 65536KTotal Submissions: 19694 Accepted: 8261
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
Source
POJ Monthly,HQM
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;int n,len;int set[1005];int is_working[1005];struct point{ int x; int y;} p[1005];int set_find(int p){ if(set[p]<0)return p; return set[p]=set_find(set[p]);}void join(int a,int b){ a=set_find(a); b=set_find(b); if(a!=b) { set[a]=b; }}bool true_dis(point a,point b){ if( ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)) <= len*len ) return 1; return 0;}int main(){ int i; cin>>n>>len; memset(is_working,0,sizeof(is_working)); memset(set,-1,sizeof(set)); for(i=1 ; i<=n; ++i) cin>>p[i].x>>p[i].y; char str; int a,b; while(cin>>str) { if(str=='O') { cin>>a; is_working[a]=1; for(i=1; i<=n; ++i) { if(is_working[i]) { if(i!=a && true_dis(p[a],p[i])) { join(i,a); set_find(i); } } } } else { cin>>a>>b; // cout<<set_find(a)<<"---"<<set_find(b)<<endl; if(set_find(a)==set_find(b)) cout<<"SUCCESS\n"; else cout<<"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 并查集
- 【Swift】学习笔记(九)——枚举
- Java对象在HotSpot虚拟机的创建、内存分布和访问
- “互联网+”为传统产业带来无限可能
- 备考SharePoint2013 Certification心得
- web 小票打印插件
- POJ---2236-Wireless Network(并查集)
- 单选按钮,复选框使用方法汇总
- Spark:一个高效的分布式计算系统
- httpmime-4.1.3.jar和httpmime-4.3.6.jar 发送的http请求有差异,导致服务端无法接收到数据。
- 模块(module)方式创建maven工程
- 医疗SEMer套用百度竞价账户技巧学习
- 认识JS
- IOS开发学习(2)-UITableView学习
- mysql 设置参照完整性