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 ...
随机推荐
- 百度地图api实例
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx ...
- html5画饼形图
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm10.aspx ...
- css 三角实例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 感知机(perceptron)
二类分类的线性分类模型,属于判别模型,利用梯度下降法对损失函数进行极小化求得感知机模型分为原始形式和对偶形式,是神经网络和支持向量机的基础 由输入控件到输出控件的如下函数: f(x)=sign(W.X ...
- document.body.scrollTop vs document.documentElement.scrollTop && document.body.scrollHeight vs document.documentElement.scrollHeight
FireFox下 document.body.scrollHeight || document.documentElement.scrollHeight;//等价 document.body.scro ...
- man手册导出成txt,pdf,html的一些小技巧
经常man一些shell命令,有时候有想导出来编辑或注释一下,所以要导出.方法有很多种,根据自己的实际需要觉得比较实用的记录下分享一下. 1.导出成txt man –t bash |col –b &g ...
- 《Programming WPF》翻译 第6章 4.应用程序全球化
原文:<Programming WPF>翻译 第6章 4.应用程序全球化 如果你打算发布你的应用程序到全球各地,你可能需要为不同地区的用户界面准备不同的版本.至少,这需要解决将文本翻译成适 ...
- C#Http编程
c# 模拟 网页实现12306登陆.自动刷票.自动抢票完全篇(转) 这一篇文章,我将从头到尾教大家使用c#模拟网页面登陆12306网站,自动刷票,选择订票人,到最后一步提交订单.研究过HTTP协议的童 ...
- qt视图选择
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from PyQt4.Qt import * from PyQt4. ...
- 【多线程】--生产者消费者模式--Lock版本
在JDK1.5发布后,提供了Synchronized的更优解决方案:Lock 和 Condition 我们使用这些新知识,来改进例子:[多线程]--生产者消费者模式--Synchronized版本 改 ...