博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2236(并查集的应用)
阅读量:4676 次
发布时间:2019-06-09

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

Wireless Network
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 35832   Accepted: 14863

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
1 #include
2 #include
3 #include
4 using namespace std; 5 const int maxn=1100; 6 bool flag[maxn]; 7 int fa[maxn],x[maxn],y[maxn]; 8 int n,d; 9 10 bool dis(int numa,int numb)11 {12 int opa,opb;13 opa=x[numa]-x[numb];14 opb=y[numa]-y[numb];15 return opa*opa+opb*opb<=d*d;16 }17 18 int find_fa(int op)19 {20 if(op!=fa[op]) fa[op]=find_fa(fa[op]);21 return fa[op]; ///此处有压缩22 }23 24 int main()25 {26 scanf("%d%d",&n,&d);27 for(int i=1;i<=n;i++){28 fa[i]=i;29 flag[i]=false;30 }31 for(int i=1;i<=n;i++)32 scanf("%d%d",&x[i],&y[i]);33 34 char order[3];35 int a,b;36 while( ~scanf("%s%d",order,&a)){37 if(order[0]=='O'){38 flag[a]=true;39 for(int i=1;i<=n;i++){40 if(i!=a&&flag[i]&&dis(i,a)){41 int iop,aop;42 iop=find_fa(i);43 aop=find_fa(a);44 fa[aop]=iop;45 }46 }47 }48 else{49 scanf("%d",&b);50 int aop,bop;51 aop=find_fa(a);52 bop=find_fa(b);53 if(aop==bop) printf("SUCCESS\n");54 else printf("FAIL\n");55 }56 }57 return 0;58 }

 

 

转载于:https://www.cnblogs.com/ZQUACM-875180305/p/9091732.html

你可能感兴趣的文章
《麻辣江湖》即将上线!
查看>>
Mybatis中mapper.xml文件判断语句中的单双引号问题
查看>>
frameset和frame
查看>>
饥饿的小易(规律,同余大数)
查看>>
ats透明代理
查看>>
PHP 小代码
查看>>
2016/03/16 codes
查看>>
2018年7月21日工作总结
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
What does the dot after dollar sign mean in jQuery when declaring variables?
查看>>
windows registry
查看>>
jquery 动画总结(主要指效果函数)
查看>>
【BZOJ4155】[Ipsc2015]Humble Captains
查看>>
【事件】阻止事件的冒泡
查看>>
mac os 安装 geckodriver
查看>>
【数据分析 R语言实战】学习笔记 第十一章 对应分析
查看>>
谁的青春不迷茫
查看>>
socket知识总结
查看>>
Qt做的简易图片浏览
查看>>