【POJ - 2236】Wireless Network (并查集)
Wireless Network
这接翻译了
Descriptions
在修复网络的过程中,工作人员可以随时进行两种操作,修复计算机或测试两台计算机是否可以通信。你的工作是回答所有的测试操作。
Input
1。“O p”(1 <= p <= N),表示修复计算机p。
2.“S p q”(1 <= p,q <= N),这意味着测试计算机p和q是否可以通信。
输入不会超过300000行。
Output
Sample Output
4 1
0 1
0 2
0 3
0 4
1
O 2
O 4
S 1 4
O 3
S 1 4
Sample Output
FAIL
SUCCESS
题目链接
https://vjudge.net/problem/POJ-2236
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100000+5
using namespace std;
int n,d;
int dx[Maxn];//坐标
int dy[Maxn];
int par[Maxn];//par[i] i的根
int pairs[Maxn];//pairs[i]=p 第i个修好的电脑编号为p
int findr(int x)//查询根
{
if(par[x]==x)
return x;
return par[x]=findr(par[x]);
}
void unite(int x,int y)//合并
{
x=findr(x);
y=findr(y);
if(x==y)//根相同不用管
return;
par[x]=y;//若根不同,y并入x,则y的根为x,同理x也能并入y 这里随意
}
double dis(int a,int b)//求距离
{
return sqrt( (double)((dx[a]-dx[b])*(dx[a]-dx[b]) + (dy[a]-dy[b])*(dy[a]-dy[b])) );
}
int main()
{
MEM(pairs,);
cin>>n>>d;
for(int i=; i<n; i++)
cin>>dx[i]>>dy[i];//集合初始化
for(int i=; i<n; i++)
par[i]=i;
int p,q,len=;
char op;
while(cin>>op)
{
if(op=='O')
{
cin>>p;
p--;
pairs[len++]=p;
for(int i=; i<len; i++)
{
if(dis(pairs[i],p)<=(double)d)//判断距离
unite(pairs[i],p);//合并集合
}
}
else
{
cin>>p>>q;
p--,q--;
if(findr(p)==findr(q))//查根
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
}
return ;
}
【POJ - 2236】Wireless Network (并查集)的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- 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 ...
随机推荐
- Git使用小技巧之回滚和撤销
想要获取更多文章可以访问我的博客 - 代码无止境. 日常的开发,我们难免会创建错误的git提交记录,整个时候git给我们提供了两个命令来解决这个问题.一个命令是git reset,另一个是git re ...
- Python3 列表的基本操作
列表索引和切片 和字符串一样,也有索引和切片,只不过切出来的内容是列表. 索引的下标从0开始. lst= ["海上钢琴师", "奥特曼", "舌尖3& ...
- centos 5.2 php升级
# gedit /etc/yum.repos.d/utterramblings.repo [utterramblings] name=Jason's Utter Ramblings Repo base ...
- CDQZ集训DAY3 日记
早上起来之后依然开始考试.然而由于校方觉得都挨在一起没有考试氛围,分了两个机房,一开始还没人去,听说另一个机房配置好了之后一堆人开始往外冲,由于我天真的数了一下我是不是要走的,晚了一步,于是乎被教练员 ...
- Java多线程下载器FileDownloader(支持断点续传、代理等功能)
前言 在我的任务清单中,很早就有了一个文件下载器,但一直忙着没空去写.最近刚好放假,便抽了些时间完成了下文中的这个下载器. 介绍 同样的,还是先上效果图吧. Jar包地址位于 FileDownload ...
- c++小游戏——俄罗斯方块
#include<cstdio> #include<windows.h> #include<ctime> int a[24][17],i,j,tim=800,ti= ...
- Ubuntu系统安装QQ等软件
1.安装deepin-wine环境:上https://github.com/wszqkzqk/deepin-wine-for-ubuntu页面下载zip包(或用git方式克隆),解压到本地文件夹,在文 ...
- Shell学习心得(四):流程控制
一.if else 1. if if 语句语法格式: if condition then command1 command2 ... commandN fi 写成一行(适用于终端命令提示符): ]; ...
- [leetcode] 486. Predict the Winner (medium)
原题 思路: 解法一: 转换比较拿取分数多少的思路,改为考虑 player拿的分数为正,把Player2拿的视为负,加上所有分数,如果最后结果大于0则Player1赢. 思考得出递归表达式: max( ...
- Java EE.JSP.动作组件
常见的JSP动作组件有以下几种: 1)<jsp:include>:在页面被请求的时候引入一个文件 2)<jsp:param>:在动作组件中引入参数信息 3)<jsp:fo ...