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 ...
随机推荐
- cmd命令。
CMD按任意退出 echo 退出……按任意键pause & exit
- mybatis 注解快速上手
一.mybatis 简单注解 关键注解词 : @Insert : 插入sql , 和xml insert sql语法完全一样 @Select : 查询sql, 和xml select sql语法完全一 ...
- web前端—工作周报
2016.07.25-2016.07.29周报: 1.本周工作主要内容: A:完成了宏视云h5播放器升级及大数据上报: B:修复xk-h5播放器bug:在三星手机自带浏览器无法进行滑动seek; C ...
- mysqldump常用参数
mysqldump常用参数说明 --all-databases 或 -A 导出全部数据库.--all-tablespaces 或 -Y 导出全部表空间--no-tablespaces 或 -y ...
- ActionBar ShareActionProvider
添加share按钮 添加share按钮的主要步骤: 1. 在ActionBar中添加share按钮 2. 从item中获取ShareActionProvider ShareActionProvider ...
- WPF中的ControlTemplate(控件模板)(转)
原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/28/690993.html WPF中的ControlTemplate(控件模板) ...
- TCP/IP TIME_WAIT状态原理
原文转载:http://elf8848.iteye.com/blog/1739571 IME_WAIT状态原理 ---------------------------- 通信双方建立TCP连接后,主动 ...
- Pre-compile (pre-JIT) your assembly on the fly, or trigger JIT compilation ahead-of-time (转)
Introduction All .NET developers know that one of the best features of the CLR is JIT-compilation: J ...
- 你已经毁了JavaScript
以前 过去我们在页面上用很时尚的方式写了一些确实很可怕的代码,它给我们带来了巨大的麻烦.可能很多人现在还在这样做,但他们不会看这篇博文,我们可以假装他们不存在. JS的伟大/了不起/让人惊讶的地方在于 ...
- Celery学习笔记
转载请注明出处:点我 我的第一篇博客!嘿嘿! 在公司实习,接触到的第一个项目就用到了Celery,之前是完全没有接触过Celery这玩意,然后花了点时间仔细的研究了下怎么用.在学习过程中也遇到了些问题 ...