A - Wireless Network POJ - 2236-kuangbin带你飞
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 50348 | Accepted: 20619 |
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
first line contains two integers N and d (1 <= N <= 1001, 0 <= d
<= 20000). Here N is the number of computers, which are numbered
from 1 to N, and D is the maximum distance two computers can communicate
directly. In the next N lines, each contains two integers xi, yi (0
<= xi, yi <= 10000), which is the coordinate of N computers. From
the (N+1)-th line to the end of input, there are operations, which are
carried out one by one. Each line contains an operation in one of
following two formats:
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
Source
[Submit] [Go Back] [Status] [Discuss]
有n个坏掉的卫星,每次操作‘O’可以修好一个,如果卫星之间都是‘修好的’状态且间距小于‘d',就可以通讯。
并查集的时候判断一下两卫星之间距离即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream> #define dbg(x) cout << #x << "=" << x << endl using namespace std;
const int maxn = ; int fa[maxn], dis[maxn];
int n,m,ans,cnt;
int d;
int canuse[maxn]; struct node {
int x, y;
}a[maxn]; void init()
{
for(int i = ; i <= n; i++) {
fa[i] = i;
}
} double cal(node a, node b) {
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} int fid(int x)
{
int r = x;
while(fa[r] != r) {
//if(cal(a[fa[r]],a[r]) <= d)
r = fa[r];
}
int i,j;///路径压缩
i = x;
while(fa[i] != r) {
//if(cal(a[fa[i]],a[r]) <= d) {
j = fa[i];
fa[i] = r;
i = j; }
return r;
} void join(int r1, int r2)///合并
{
int fidroot1 = fid(r1), fidroot2 = fid(r2);
if(fidroot1 != fidroot2) {
fa[fidroot2] = fidroot1;
}
} int main()
{
scanf("%d %d",&n, &d);
init();
for(int i = ; i <= n; ++i) {
scanf("%d %d",&a[i].x, &a[i].y);
}
getchar();
char ch[];
int p,q;
int cnt = ;
while(scanf("%s", ch) != EOF) {
//dbg(ch[0]);
if(ch[] == 'O') {
scanf("%d",&p);
//getchar();
canuse[cnt++] = p;
for(int i = ; i < cnt-; ++i) {
if(cal(a[canuse[i]],a[p]) <= double(d)) {
join(canuse[i],p);
}
}
}
if(ch[] == 'S') {
scanf("%d %d",&p,&q);
//getchar(); //join(p,q);
if(fid(p) == fid(q)) {
puts("SUCCESS");
}
else {
puts("FAIL");
}
}
}
return ;
}
A - Wireless Network POJ - 2236-kuangbin带你飞的更多相关文章
- Wireless Network(POJ 2236)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20724 Accepted: 871 ...
- Day5 - B - Wireless Network POJ - 2236
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- DisJSet:Wireless Network(POJ 2236)
无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...
- Wireless Network POJ - 2236 (并查集)
#include<iostream> #include<vector> #include<string> #include<cmath> #includ ...
- A - Wireless Network POJ - 2236
题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...
- 迷宫问题 POJ - 3984 [kuangbin带你飞]专题一 简单搜索
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- 棋盘问题 POJ - 1321 [kuangbin带你飞]专题一 简单搜索
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. ...
随机推荐
- Linux内存管理解析(二) : 关于Linux内存管理的大体框架
什么是内存管理 ? 首先内存管理管理的主要对象是虚拟内存,但是虚拟内存对应的映射主要为物理内存,其次也可能通过交换空间把虚拟内存与硬盘映射起来,既然如此,那我们先了解物理内存的管理. 对于物理内存而言 ...
- Oracle导出警告“EXP-00003: 未找到段 (0,0) 的存储定义”解决
环境:CentOS7.4 Oracle11.2.0.4(搭建rac集群) 问题描述:在使用exp命令执行导出的时候,部分表提示“EXP-00003: 未找到段 (0,0) 的存储定义”警告. 问题 ...
- MySQL 什么是事务?
该文为< MySQL 实战 45 讲>的学习笔记,感谢查看,如有错误,欢迎指正 一.事务简介 事务就是为了保证一组数据库操作,要么全部成功,要么全部失败. 事务是在引擎层实现的,也就是说并 ...
- PHPJN0001:phpmyadmin 允许密码为空 设置
phpmyadmin连接mysql数据库,出于安全考虑,默认不允许使用空密码连接数据库.因为数据库一般都设置密码访问. 但如果只是本机环境测试使用,每隔一段时间都需要填写密码,不是很方便. 如果没有修 ...
- win下python脚本以unix风格换行保存将会报错为编码问题 SyntaxError: encoding problem:gbk
utf-8与gbk编码都报错 从别人的github拉下来一个python脚本. 直接运行,python报错如下: File ".\drag_files_do_event.py", ...
- 返回一个整数数组中最大子数组的和——java程序设计
一.题目要求 1.输入一个整形数组,数组里有正数也有负数.2.数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和.3.求所有子数组的和的最大值.要求时间复杂度为O(n) 二.设计思想 解决 ...
- 将short类型转换为char类型
void short2char(uint8_t *arr1, uint16_t *arr2, int len) { ; ; for (x; x < len; x++) { arr1[x++] = ...
- [更新ing]zzy的家里蹲网课日记
前言 精神小(ge)伙(zi)终于记起了他的博客密码...... 寒假以来,积累了巨多的好想法想要写博客,往往都是因为各种原因半途而废--在学习生活上甚至也有各种拖延的毛病:爱欠作业不早睡,不见成绩不 ...
- Ubuntu P40显卡配置CUDA 10.1,CUDNN 7.6,Conda 5.2.0, Tensorflow-gpu 1.8
1. 安装CUDA 禁用nouveau vim /etc/modprobe.d/blacklist.conf 最后两行加入 blacklist nouveau options nouveau mode ...
- C# WPF从RIOT API获取数据(RIOT代表作品《英雄联盟》)
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF从RIOT API获取数据(RIOT代表作品<英雄联盟>) 阅读导航 ...