博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2236(KB5-A)
阅读量:4310 次
发布时间:2019-06-06

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

Wireless Network

Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 28617   Accepted: 11842

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

Source

,HQM
 
简单并查集
1 //2017-07-17 2 #include 
3 #include
4 #include
5 6 using namespace std; 7 8 const int N = 1010; 9 int n, d;10 int fa[N], x[N], y[N];11 bool isRepaired[N];12 13 void init(){14 for(int i = 0; i < N; i++){15 fa[i] = i;16 isRepaired[i] = false;17 }18 }19 20 int getfa(int x){21 if(fa[x] == x)return x;22 return fa[x] = getfa(fa[x]);23 }24 25 void merge0(int a, int b){26 int af = getfa(a);27 int bf = getfa(b);28 if(af != bf){29 fa[bf] = af;30 }31 }32 33 int main(){34 char op[3];35 int a, b;36 while(scanf("%d%d", &n, &d) != EOF){37 init();38 for(int i = 1; i <= n; i++){39 scanf("%d%d", &x[i], &y[i]);40 }41 getchar();42 while(scanf("%s", op)!=EOF){43 if(op[0] == 'O'){44 scanf("%d", &a);45 isRepaired[a] = true;46 for(int i = 1; i <= n; i++){47 if(isRepaired[i] && (x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a])<=d*d){48 merge0(i, a);49 }50 }51 }else{52 scanf("%d%d", &a, &b);53 int af = getfa(a);54 int bf = getfa(b);55 if(af == bf) printf("SUCCESS\n");56 else printf("FAIL\n");57 }58 }59 }60 61 return 0;62 }

 

转载于:https://www.cnblogs.com/Penn000/p/7197972.html

你可能感兴趣的文章
【timeisprecious】【JavaScript 】JavaScript RegExp 对象
查看>>
How to set colors of HTML tables
查看>>
Cannot parse POST parameters of request: '<URL>'
查看>>
Hibernate 关联映射
查看>>
PHP语法2
查看>>
python unittest学习1---重要的几个概念
查看>>
MapReduce编程之Reduce Join多种应用场景与使用
查看>>
干货: 可视化项目实战经验分享,轻松玩转 Bokeh (建议收藏)
查看>>
使用pyinstaller打包多个py文件为一个EXE文件
查看>>
书接前文,用多进程模式实现fibonnachi并发计算
查看>>
numpy的数组常用运算练习
查看>>
ExtJs之DHTML,DOM,EXTJS的事件绑定区别
查看>>
Leetcode:Toeplitz Matrix
查看>>
js定时器
查看>>
Android官方文档
查看>>
tcp/udp协议代码实现
查看>>
python---django中orm的使用(2)
查看>>
读书时间《JavaScript高级程序设计》四:BOM,客户端检测
查看>>
Linux基础命令---free显示内存使用
查看>>
转:CentOS---网络配置详解
查看>>