Wireless Network(POJ 2236)
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 20724 | Accepted: 8711 |
Description
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
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
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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
#define Max 1005
int n,d;
int per[Max];
bool vis[Max];
struct point
{
int x,y;
}e[];
void init()
{
for(int i=;i<=n;i++)
per[i]=i;
return;
}
int find(int x)
{
if(x==per[x])
return x;
int tem,root=x,t=x;
while(root!=per[root]) root=per[root];
while(t!=per[t])
{
tem=per[t];
per[t]=root;
t=tem;
}
}
bool dis(int q,int p)
{
point a=e[q],b=e[p];
int f=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
return d*d>=f;
}
int unite(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
per[a]=b;
return ;
}
int main()
{
int i,j;
int v,u,p;
char ch;
freopen("in.txt","r",stdin);
scanf("%d%d",&n,&d);
init();
memset(vis,,sizeof(vis));
for(i=;i<=n;i++)
scanf("%d%d",&e[i].x,&e[i].y);
getchar();
while(scanf("%c",&ch)!=EOF)
{
if(ch=='S')
{
scanf("%d%d",&u,&v);
if(find(u)==find(v))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
else if(ch=='O')
{
scanf("%d",&u);
vis[u]=;
for(i=;i<=n;i++)
if(vis[i]&&i!=u&&dis(i,u))
unite(u,i);
}
getchar();
}
return ;
}
Wireless Network(POJ 2236)的更多相关文章
- Day5 - B - Wireless Network POJ - 2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- DisJSet:Wireless Network(POJ 2236)
无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...
- Wireless Network POJ - 2236 (并查集)
#include<iostream> #include<vector> #include<string> #include<cmath> #includ ...
- A - Wireless Network POJ - 2236
题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...
- A - Wireless Network POJ - 2236-kuangbin带你飞
A - Wireless Network POJ - 2236 Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 50348 ...
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
随机推荐
- CActiveForm提示中文化
一般情况下,yii框架的CActiveForm组建的提示是英文的,把它改成中文提示 首先在main.php配置文件中,设置 'language'=>'zh_cn'; 这样将会使得cannot b ...
- 单片机 认识HEX文件
看过几篇常用指令的用法后,我们换换口味,介绍一下Intel 原厂所公布的HEX文件标准格式,相信经过本文的介绍,一定可以让您对8051的操作有更进一步的认识.以下是一个程序经编译器编译后所得到的HEX ...
- 通用Makefile
本文推荐了一个用于对 C/C++ 程序进行编译和连接以产生可执行程序的通用 Makefile. 在使用 Makefile 之前,只需对它进行一些简单的设置即可:而且一经设置,即使以后对源程序文件有所增 ...
- Merge Sorted Array 解答
Question Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- Colorful Lecture Note(手工栈)
题目1 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorithm ...
- python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客
python海明距离 - 5IVI4I_I_60Y的日志 - 网易博客 python海明距离 2009-10-01 09:50:41| 分类: Python | 标签: |举报 |字号大中小 ...
- xsank的快餐 » Python simhash算法解决字符串相似问题
xsank的快餐 » Python simhash算法解决字符串相似问题 Python simhash算法解决字符串相似问题
- ps查看内存占用排序
ps -eo rss,pmem,pcpu,vsize,args | sort -k 1 -r -n | less 解析一下: ps 都知道,是linux,unix显示进程信息的, -e 是显示所有进程 ...
- Android基础&进阶
http://blog.csdn.net/liuhe688/article/details/9494411