A - Wireless Network——POJ
来源:互联网 发布:linux svn服务端搭建 编辑:程序博客网 时间:2024/06/05 10:46
A - Wireless Network
Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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
#include<stdio.h>#include<string.h>#include<math.h>#include <iostream>using namespace std;int distance(int x,int y,int x1,int y1);int getf(int v);typedef struct {int x;int y;}Piont;Piont e[1010];int dis[1010];int num[1010];int main(){char str[100];int n,d,i,j,x,y,a,b;scanf("%d %d",&n,&d);for(i=1;i<=n;i++) dis[i]=i;for(i=1;i<=n;i++){scanf("%d %d",&e[i].x,&e[i].y);}int len=0;//表示已经修好的 while(scanf("%s",str)!=EOF){if(str[0]=='O'){scanf("%d",&num[len]);for(j=0;j<len;j++)//每加入一个与集合中的点一一合并 {if(distance(e[num[len]].x,e[num[len]].y,e[num[j]].x,e[num[j]].y)<=d*d){a=getf(num[len]);b=getf(num[j]);if(a!=b)dis[a]=b;}}len++;}else if(str[0]=='S'){scanf("%d %d",&x,&y);if(getf(x)==getf(y))printf("SUCCESS\n");else printf("FAIL\n");}}return 0;} int getf(int v)//找祖先 {if(dis[v]!=v){dis[v]=getf(dis[v]);}return dis[v];}int distance(int x,int y,int x1,int y1)//计算路径 {return (x-x1)*(x-x1)+(y-y1)*(y-y1);}
0 0
- A - Wireless Network——POJ
- 刷题——Wireless Network POJ
- 【并查集变形】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 2236 Wireless Network
- POJ 2236Wireless Network
- 通过hexo+github建立博客
- 支付宝的demo运行错误
- 数据库设计三大范式
- VS2013+QT5开发环境配置 win7_64
- acm_最长子序列
- A - Wireless Network——POJ
- 树莓派自动运行应用程序(脚本及图形界面)
- Linux Shell文本处理命令技巧
- C++ 从数据库读取数据,将数据显示在界面上的TreeCtrl上
- 深搜文件夹中的最大文件
- thrift TBinaryProtocol 数据传输格式
- Hadoop WordCount运行详解
- Node中的全局变量和全局对象
- 63. Unique Paths II 找唯一途径2(中间有路障)