POJ2236——Wireless Network
来源:互联网 发布:中国8个一线城市 知乎 编辑:程序博客网 时间:2024/06/05 11:52
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<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int father[1010];double dis[1010][1010];bool is_good[1010];struct list{int x,y;}point[1010];int find(int x){if(father[x]==-1)return x;return father[x]=find(father[x]);}void init(){memset(father,-1,sizeof(father));memset(dis,0,sizeof(dis));memset(is_good,0,sizeof(is_good));}void merge(int x,int y){int a=find(x);int b=find(y);if(a!=b)father[a]=b;}double dist(int x1,int y1,int x2,int y2){return sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));}int main(){int n;double d;while(~scanf("%d%lf",&n,&d)){int x,y;init();for(int i=1;i<=n;i++)scanf("%d%d",&point[i].x,&point[i].y);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=dist(point[i].x,point[i].y,point[j].x,point[j].y);//for(int i=1;i<=n;i++)//for(int j=1;j<=n;j++)//printf("%d--%d %f\n",i,j,dis[i][j]); char op[3];while(scanf("%s",op)==1){if(op[0]=='O'){scanf("%d",&x);is_good[x]=1;for(int i=1;i<=n;i++)if(i!=x && is_good[i] && dis[x][i]<=d)merge(x,i);}else{scanf("%d%d",&x,&y);if(find(x)==find(y))printf("SUCCESS\n");elseprintf("FAIL\n");}}}return 0;}
0 0
- POJ2236——Wireless Network
- poj2236——Wireless Network(并查集)
- POJ2236——Wireless Network 并查集应用
- POJ2236 Wireless Network
- poj2236 - Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236---Wireless Network
- POJ2236--Wireless Network
- poj2236 Wireless Network
- poj2236 Wireless Network
- POJ2236-Wireless Network
- POJ2236(Wireless Network)
- POJ2236 Wireless Network
- poj2236 Wireless Network
- POJ2236 Wireless Network
- 越来越烦
- 更适合学习的产品级cortex-A9 安卓开发板
- system property
- 下载就这么难吗?
- Old Calculator
- POJ2236——Wireless Network
- 关于剩余时间
- swift xmpp代码学习
- SQL Server 可更新订阅的发布和订阅的数据库文件迁移
- [iOS]深入浅出 iOS 之多线程 NSThread
- 下载的问题
- smarty学习 -基础配置
- Java 不可变类
- freetype第二部分