POJ 2236:Wireless Network(并查集)
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 36363 | Accepted: 15086 |
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
题意:对一些损坏的电脑进行维修,如果两个电脑相连,且距离小于d,则这两个电脑间可以相互通信。第一行输入n和d分别代表电脑的个数和能够通信的距离,接下来n行表示n台电脑的坐标。接下来如果开头输入O(注意是字母O不是数字0),继续输入一个数字p表示维修第p台电脑。如果输入S,继续输入两个数p,q,表示询问这两台电脑间是否可以通信,如果能,输出SUCCESS,如果不能,输出FAIL
就是一道并查集模板题,但是要多加一个对两点间距离的判断,最后输入S后,查询p和q的根节点是否相同,如果相同,则可以通信
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
const int maxn=1e6+10;
int a[maxn];
int flag[maxn];
int d;
struct wzy
{
int x,y;
}p[maxn];
int find(int x)
{
if(x!=a[x])
return find(a[x]);
return a[x];
}
void join(int x,int y)
{
int dx=find(x);
int dy=find(y);
if(dy!=dx)
{
a[dx]=dy;
}
}
int vis(int a,int b)
{
if ((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y)<=d*d)//a,b两点距离如果小于d
return 1;
else
return 0;
}
int main(int argc, char const *argv[])
{
int n;
std::cin>>n>>d;
for(int i=1;i<=n;i++)
{
flag[i]=0;
a[i]=i;
}
for(int i=1;i<=n;i++)
{
std::cin>>p[i].x>>p[i].y;
}
char ch;
int x,y;
getchar();
while(std::cin>>ch)
{
if(ch=='O')
{
std::cin>>x;
flag[x]=1;
for(int i=1;i<=n;i++)
{
if(flag[i]&&vis(i,x)&&i!=x)//判断电脑是否修好,两点距离是否小于d
join(i,a[x]);//合并节点
}
}
else if(ch=='S')
{
std::cin>>x>>y;
//判断x和y的根节点
a[x]=find(x);
a[y]=find(y);
if(a[x]!=a[y])
std::cout<<"FAIL"<<std::endl;
else
std::cout<<"SUCCESS"<<std::endl;
}
}
return 0;
}
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 ...
随机推荐
- idea中使用插件lombok简化java bean的getter/setter/log等常用功能
一.安装. 1. 2. 3. 4. . 二.使用 1. 2. 3. 结果分析,如果没有添加@Setter注解,则LombokTest中的student示例无法使用setAge()等方法.使用lombo ...
- 解决 failed to push some refs to 'git@github.com:zle1992/head-first-java' hint: Updates were rejected because the tip of your curr
问题描述: 寒假之前用实验室电脑push到github 上head first java 的程序,寒假回家后,想用自己的笔记本继续编,继续push . 我先从github下载zip到本地,然后 解压后 ...
- 牛客国庆集训派对Day3 Solution
A Knight 留坑. B Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespa ...
- Spring-Boot 中 Redis 的简单使用以及简单模糊匹配删除
https://yulaiz.com/spring-boot-redis-simple/
- Mybatis的executor
前提:一级缓存与二级缓存,可见:https://www.cnblogs.com/yanze/p/10175017.html 简介: Executor与SqlSession绑定在一起,每一个SqlSes ...
- 我是如何通过debug成功甩锅浏览器的:解决fixed定位元素,在页面滚动后touch事件失效问题
如果你关注我应该知道,我最近对PC端页面进行移动适配.在这个过程中,为了节省用户300ms的时间,同时给予用户更及时的点击反馈(这意味着更好的用户体验),我在尝试使用移动端独有的 touchstart ...
- NOI导刊 2009 提高二
开灯 题目大意 对编号为\([i \times a]\)的灯进行操作,找出操作数为奇数的那一个 题目分析 难度: 入门 因为看到操作数为奇数,因此直接进行位运算,做亦或和 打砖块 题目分析 第一眼看上 ...
- POJ 2762 Going from u to v or from v to u? (判断单连通)
http://poj.org/problem?id=2762 题意:给出有向图,判断任意两个点u和v,是否可以从u到v或者从v到u. 思路: 判断图是否是单连通的. 首先来一遍强连通缩点,重新建立新图 ...
- PHP中__autoload()与spl_autoload_register()函数的用法与区别
_autoload() 函数在PHP文档中的解释是试图使用尚未被定义的类时自动调用.通过调用此函数,脚本引擎在 PHP 出错失败前有了最后一个机会加载所需的类. 如何理解这句话,我们首先看下面一个简单 ...
- sudo环境变量问题;程序库函数寻找
1. sudo 和 root不完全等效,继承的环境变量不一样,最主要的区别还是输入的密码不同. 2. 使用sudo去执行一个程序时,出于安全的考虑,这个程序将在一个新的.最小化的环境中执行,也就是说, ...