博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ - 2236 Wireless Network
阅读量:6994 次
发布时间:2019-06-27

本文共 2750 字,大约阅读时间需要 9 分钟。

Wireless Network
题目链接:
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 27292   Accepted: 11291

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. 

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. 

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
#include
#include
#include
#include
using namespace std;const int N=1000+5;int par[N],rank[N];void init(int n){ for(int i=0;i<=n;i++) { par[i]=i; rank[i]=0; }}int find(int x){ if(par[x]==x)return x; else return par[x]=find(par[x]);}void unite(int x,int y){ x=find(x); y=find(y); if(x==y)return ; if(rank[x]
>n>>d; init(n); for(int i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); } getchar(); int vis[N]={ 0 }; int v[300000+5]; int c=0; int a; char ch; while(cin>>ch) { if(ch=='O') { cin>>a; vis[a]=1; v[c++]=a; for(int i=0;i
>a>>b; if(find(a)==find(b)&&vis[a]&&vis[b])cout<<"SUCCESS"<

 

转载于:https://www.cnblogs.com/widsom/p/6729833.html

你可能感兴趣的文章
MySQL配置文件my.cnf优化详解
查看>>
MySQL完整性约束
查看>>
ssh 配置config 别名
查看>>
eclipse查看类源码出现failed to create the part's controls的解决方法
查看>>
Kafka学习之四 Kafka常用命令
查看>>
ruby 【rails在win7_64位操作系统安装】
查看>>
回溯法--0-1背包问题
查看>>
ubuntu hadoop集群 master免密码登陆到slave节点
查看>>
css3的背景多重运用
查看>>
关于 [栈溢出后jmp esp执行shellcode] 原理分析
查看>>
安全疏散(一)
查看>>
python_sort(key=) 的使用
查看>>
UT源码116
查看>>
git仓库远程连接GitHub
查看>>
Mysql配置参数说明
查看>>
Hello world,Hello 2015,Bye 2014
查看>>
asp.net中使用单例
查看>>
[Asp.Net]状态管理(Session、Application、Cache)
查看>>
mysql 跨服务器复制数据库
查看>>
用递归删除各种节点
查看>>