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 ...
随机推荐
- [原创]零基础R语言教程---第二课---R语言入门
这节教程简单描述了R语言中常用的数据类型, 向量,字符串,矩阵,列表,数据框,以及附带了一个小例子 对于这节课所附带的例子需要做下列补充: 1.这个例子面向于对整列的数据进行预测 2.如果你需要求单行 ...
- Honkly分享链接集总篇
VC6.0 Filetool Honkly版 http://pan.baidu.com/s/1bnentr5 密码:15eq,解压密码:honkly VC6.0 Filetool 官方 ...
- Qt HTTP请求同步调用
在Qt中,进行HTTP就行现在官方提倡使用QNetworkAccessManager,其和QNetworkRequest和QNetworkReply配合使用,来完成,其是只支持异步的操作.最近使用QM ...
- .NET 使用unity实现依赖注入
原文地址:http://www.cnblogs.com/wujy/p/3317795.html 一:理论部分 依赖注入:这是 Ioc 模式的一种特殊情况,是一种基于改变对象的行为而不改变类的内部的接口 ...
- poj 1017 Packets 贪心
题意:所有货物的高度一样,且其底面积只有六种,分别为1*1 2*2 3*3 4*4 5*5 6*6的,货物的个数依次为p1,p2,p3,p4,p5,p6, 包裹的高度与货物一样,且底面积就为6*6,然 ...
- 【转】Windows与Linux(Ubuntu)双系统时间不一致的解决方法
当在嵌入式Linux里面备份文件时候,在备份的时候,PC(win7)和开发板的时间都是9:30,但是在开发板发现文件创建时间是9:30,然后u盘插在PC(win7)上,发现文件创建时间是1:30,为什 ...
- Gym Class(拓扑排序)
Gym Class Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- vc10的C2664和C2065错误
在vs2010中编译一个普通的C++程序(Win32 Console Application),都会出现这两个错误! 究其原因是:我们已经习惯了VC6的种种简陋和不规范! 例如,下列程序在VC6中编译 ...
- Python 获取Facebook用户Friends的爱好类别中的Top10
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-12 @author: guaguastd @name: f ...
- Android应用程序线程消息循环模型分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6905587 我们知道,Android应用程序是 ...