poj 2236 Wireless Network
来源:互联网 发布:科比勤奋 知乎 编辑:程序博客网 时间:2024/05/29 14:14
Wireless Network
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 30934 Accepted: 12865
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 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4
Sample Output
FAIL
SUCCESS
#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>using namespace std;#define maxn 1100int pre[maxn];struct node{ double x,y; int vis;}a[1500];int findroot(int num){ while(pre[num] != num) { num = pre[num]; } int temp = num; while(pre[temp] != num) { int j = pre[temp]; pre[temp] = num; temp = j; } return num;}void mix(int a,int b){ int roota = findroot(a); int rootb = findroot(b); if(roota != rootb) { pre[roota] = rootb; }}double dis(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int main(){ int n,d; while(~scanf("%d%d",&n,&d)) { for(int i = 1; i <= n; i++) { pre[i] = i; } for(int i =1; i <= n; i++) { scanf("%lf%lf",&a[i].x,&a[i].y); a[i].vis = 0; } char s; while(~scanf(" %c",&s)) { if(s == 'O') { int num; scanf("%d",&num); a[num].vis = 1; for(int i = 1; i <= n; i++) { if(i == num) continue; if(dis(a[num],a[i]) <= d && a[i].vis == 1) { mix(num,i); } } } else { int x,y; scanf("%d%d",&x,&y); if(findroot(x) == findroot(y)) { printf("SUCCESS\n"); } else printf("FAIL\n"); } } } return 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 2236Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- iptables的讲解
- Java Activiti(11)---整合到springMVC项目的详细配置
- js创建对象的方式
- C++中的 peek()、get()、getline()
- Video.js自定义使用
- poj 2236 Wireless Network
- 吴恩达推荐好文:中国人工智能的崛起
- java封装中关于set()和get()的用法
- 二叉树的数组实现
- 一个关于git的小问题
- CSS布局——水平居中
- HDOJ2056_Rectangles
- [C/C++]硬货 数据库开发之mysql
- 全功能音视频互动开发平台