POJ 2236 Wireless Network [并查集+几何坐标 ]
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 [题意]:
二维平面有N台坏的电脑,给出所有电脑的坐标(X,Y)。然后给出2种指令:
O U 指令表示修复编号为U的电脑(电脑只有被修复之后才能进行数据连接)。
S U V 指令要求你返回 编号U电脑和 编号V电脑是否可以进行数据连接(只有U和V电脑同时被修复且连通才行)。
现在给出一个距离d,只有两台被修复的电脑且他们之间的距离<=d时才可以进行连通。且如果A与C连通,C与B连通,那么A与B可以通过C连通(也算A与B连通了)。
现在要你回答每一条S U V指令,如果U与V连通,输出SUCCESS ,否则输出FAIL。
[分析]:
每修复一台电脑,就把它与所有距离它不超过D且已经被修复的电脑连通(即合并两者的连通分量)。每次查询只需要看被查询的两台电脑是否被修复且都在同一个连通分量即可。
[代码]:
#include<iostream>
#include<algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int fa[maxn],vis[maxn];
int n,d;
struct node
{
int x,y;
}p[maxn]; void init()
{
for(int i=;i<=n;i++)
fa[i]=i;
memset(vis,,sizeof(vis));
} int find(int x)
{
return fa[x]==x?x:find(fa[x]);
} void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
fa[fx]=fy;
} bool dis(int x, int y){
float a = p[x].x - p[y].x;
float b = p[x].y - p[y].y;
if(a * a + b * b <= d * d) return true;
else return false;
}
int main()
{
char s[];
int x,y,a,b; scanf("%d%d",&n,&d); for(x=;x<=n;x++)
scanf("%d %d",&p[x].x , &p[x].y); init();
while(~scanf("%s",s))
{
if(s[] == 'O')
{
scanf("%d",&x);
vis[x]=;
for(y=;y<=n;y++)
{
if(vis[y] && dis(x,y))
join(x,y);
}
}
else
{
scanf("%d %d",&x, &y);
if(vis[x] && vis[y] && find(x) == find(y))
printf("SUCCESS\n");
else
printf("FAIL\n");
}
}
}
09/15
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 ||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 ...
随机推荐
- 【bzoj3122】[Sdoi2013]随机数生成器 BSGS思想的利用
题目描述 给出递推公式 $x_{i+1}=(ax_i+b)\mod p$ 中的 $p$.$a$.$b$.$x_1$ ,其中 $p$ 是质数.输入 $t$ ,求最小的 $n$ ,使得 $x_n=t$ . ...
- BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】
题目 Moving Pebbles Two players play the following game. At the beginning of the game they start with ...
- picks loves segment tree I
picks loves segment tree I 题目背景 来源: \(\text {2018 WC Segment Tree Beats}\) 原作者: \(\text {C_SUNSHINE} ...
- LaTeX的图片插入及排版[转]
LaTeX中一般只直接支持插入eps(Encapsulated PostScript)格式的图形文件, 因此在图片插入latex文档之前应先设法得到图片的eps格式的文件. UNIX下的各种应用软件都 ...
- 怎么替换jar包里面的文件?
很多时候,我们需要替换包含在jar包里面的文件,例如修改里面的配置文件. 由于jar包已经生成,在不想重新用eclipse导出的情况下,我们怎么修改jar包里面的文件呢? 其实说出来很简单,可以使用以 ...
- ansible+docker
1.准备镜像: 1007 docker run -itd --name client2 ff37bc5ab732 1008 docker run -itd --name client ff37bc5a ...
- 精通JS正则表达式(转)
精通JS正则表达式,讲的比较详细,学习正则表达式的朋友可以参考下. 正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡 ...
- 组合数学--Polya 原理及典型应用
Redfield-Polya (Pólya enumeration theorem,简称PET)定理是组合数学理论中最重要的定理之一.自从 1927 年 Redfield 首次运用 group red ...
- 【EOJ3654】管理孩子(贪心,二分)
题意:有一棵n个点的树,其中有k个是关键点,将树分割成若干部分,每部分至少包含一个关键点,求最大分割大小的最小值 思路: 最后特判一下f[1]的值 #include<cstdio> #in ...
- DotNETCore 学习笔记 异常处理
Error Handling public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseIISP ...