POJ 2236 Wireless Network (并查集)
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 18066 | Accepted: 7618 |
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 <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std; const int SIZE = ;
int FATHER[SIZE],RANK[SIZE];
int N,D;
pair<int,int> G[SIZE];
vector<int> OK;
double DIS[SIZE][SIZE]; void ini(int);
int find_father(int);
void unite(int,int);
bool same(int,int);
double dis(pair<int,int>,pair<int,int>);
int main(void)
{
int x,y;
char ch; while(scanf("%d%d",&N,&D) != EOF)
{
ini(N);
for(int i = ;i <= N;i ++)
scanf("%d%d",&G[i].first,&G[i].second);
for(int i = ;i <= N;i ++)
for(int j = ;j <= N;j ++)
DIS[i][j] = dis(G[i],G[j]); while(scanf(" %c",&ch) != EOF)
if(ch == 'O')
{
scanf("%d",&x);
for(int i = ;i < OK.size();i ++)
if(DIS[x][OK[i]] <= D)
unite(x,OK[i]);
OK.push_back(x);
}
else
{
scanf("%d%d",&x,&y);
printf("%s\n",same(x,y) ? "SUCCESS" : "FAIL");
}
} return ;
} void ini(int n)
{
for(int i = ;i <= n;i ++)
{
FATHER[i] = i;
RANK[i] = ;
}
} int find_father(int n)
{
if(FATHER[n] == n)
return n;
return FATHER[n] = find_father(FATHER[n]);
} void unite(int x,int y)
{
x = find_father(x);
y = find_father(y); if(x == y)
return ;
if(RANK[x] < RANK[y])
FATHER[x] = y;
else
{
FATHER[y] = x;
if(RANK[x] == RANK[y])
RANK[y] ++;
}
} bool same(int x,int y)
{
return find_father(x) == find_father(y);
} double dis(pair<int,int> a,pair<int,int> b)
{
return sqrt(pow(a.first - b.first,) + pow(a.second - b.second,));
}
POJ 2236 Wireless Network (并查集)的更多相关文章
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- 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 ...
- POJ 2236 Wireless Network(并查集)
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
随机推荐
- F5 负载均衡 相关资源
F5负载均衡之检查命令的说明http://net.zdnet.com.cn/network_security_zone/2010/0505/1730942.shtml F5培训http://wenku ...
- [MySQL] 字符集和排序方式
字符串类型 MySQL的字符串分为两大类: 1)二进制字符串:即一串字节序列,对字节的解释不涉及字符集,因此它没有字符集和排序方式的概念 2)非二进制字符串:由字符构成的序列,字符集用来解释字符串的内 ...
- Labeled ContentControl & LabeledControl【项目】
LabeledTextBoxControl: C#定义 using System; using System.Collections.Generic; using System.Linq; using ...
- ActiveMQ讯息传送机制以及ACK机制详解
[http://www.ylzx8.cn/ruanjiangongcheng/software-architecture-design/11922.html] AcitveMQ:消息存储和分发组件,涉 ...
- [hihoCoder]#1039 : 字符消除
Description 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的: 1)如果s包含长度超过1的由相同字母组成的子串,那么这些 ...
- Django官方文档学习2——数据库及模板
网址:https://docs.djangoproject.com/en/1.10/intro/tutorial02/ 1.扫描installed_apps,创建需要的数据库table python ...
- 六、Linux/UNIX操作命令积累【kill、netstat、df、du】
在使用Linux/UNIX下,常常会使用文本界面去设置系统或操作系统,作者本人在工作的过程也在不断接触这方面的命令,所以为此特酝酿.准备.開始了本文的编写. 本文主要记录自己平时遇到的一些Linux/ ...
- C++ for循环效率
1.考虑二维数组,在C++中,以先行后列的方式存储连续的数组元素.也就是同一行的元素在一起,同一列的元素之间有间隔,且间隔相同.理想情况下,二维数组的元素是随机访问的,可以直接定位,即i*列数+j.因 ...
- boost::token_compress_on
对于场景:string s = "123456",用"3","4"切分,默认情况下(boost::token_compress_off),切 ...
- 窗口界面编程之一:VB实现简单异形窗口
一.运行效果图(在Win8里的运行效果,在XP里运行就不能体现出来,因为我使用的XP的界面效果) 二.编译环境:Visual Basic 6.0 (SP6) 三.实现原理:通过区域合并 四.使用API ...