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 ...
随机推荐
- 一次org.springframework.jdbc.BadSqlGrammarException ### Error querying database Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException问题排查过程
先说结论: 因为在表设计中有一个商品描述字段被设置为desc,但desc是mysql中的关键字,如select id,name,desc,price from product;这条sql语句在查询时的 ...
- 20155207 2016-2017-2 《Java程序设计》第八周学习总结
20155207 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 第15章 通用API 15.1 日志 15.1.1 日志API简介 java.util.lo ...
- CyclicBarrier实现流水处理服务类
package com.yzu.zhang.thread.concurrent; import java.util.Map.Entry; import java.util.Random; import ...
- Vue学习笔记之Vue的面向对象
0x00 准备工作 JavaScript 语言中,生成实例对象的传统方法是通过构造函数. function Animal(name,age){ this.name = name; this.age = ...
- JS地址自动返填技术
系统设计地址为省市县三级联动,规范是规范了,但是无形中增加了系统操作的时间成本,因此设计地址自动返填技术,只要把地址拷贝到详细地址框中,可以自动返填到省市县三级联动的下拉框中. 还好洒家的大学不是混过 ...
- iptables命令、规则、参数详解
表 (table)包含4个表:4个表的优先级由高到低:raw-->mangle-->nat-->filterraw---RAW表只使用在PREROUTING链和OUTPUT链上 ...
- Signing package index... Cannot open file '/home/jello/openwrt/key-build' for reading
一.环境 发行版:Ubuntu 18.04.1 LTS 代号:bionic 内核版本:4.15.0-30-generic 二.背景 在编译Openwrt/LEDE时出现以下错误,进而自动终止了编译: ...
- Springboot与日志
日志框架 比如开发一个大型系统:1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件?2.框架来记录系统的一些运行时信息:日志框架 :riz ...
- 框架-springmvc源码分析(一)
框架-springmvc源码分析(一) 参考: http://www.cnblogs.com/heavenyes/p/3905844.html#a1 https://www.cnblogs.com/B ...
- codeforces 11 B.Jumping Jack 想法题
B. Jumping Jack Jack is working on his jumping skills recently. Currently he's located at point zero ...