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. ...
随机推荐
- Leetcode:110. 平衡二叉树
Leetcode:110. 平衡二叉树 Leetcode:110. 平衡二叉树 点链接就能看到原题啦~ 关于AVL的判断函数写法,请跳转:平衡二叉树的判断 废话不说直接上代码吧~主要的解析的都在上面的 ...
- toj 3616 Add number (没想到啊~~)
Add number 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交: 60 测试通过: 21 描述 Employees of Baidu like ...
- npm常用命令和脚手架使用
最近前端同学使用最多的莫过于vue,angualr,react等热门前端框架了.那么就避免不掉的使用npm命令,本人就经常因为这三个脚手架的使用而不得不百度相应的npm命令,不胜其烦,,,因此就整理一 ...
- jmeter-json提取器提取的内容含”引号
这时如果直接赋值会报错 解决方法: 1.用vars.get("Object")提取变量的值 2.用代码提取,最后把提取到的Object或Array转为String
- Electron+Vue – 基础学习(2): 项目打包成exe桌面应用
项目创建完成,启动正常,接下来就是项目打包了.将测试Demo打包成exe桌面应用,点击exe文件,运行项目. 书接上文,创建项目有三种方式 Git拷贝.直接创建:通过electron社群提供的命令行工 ...
- python函数的使用
python函数的使用 制作人:全心全意 函数的定义 def 函数名(参数): 函数体 参数的使用 def 函数名(a): 函数体 函数名(5) 默认函数 def 函数名(a=5): 函数体 函数名( ...
- 学习R语言的一点小心得
1.目前R 语言处于入门阶段吧,能够执行一些简单的模型了,还是有收获的. 但是在跑模型的时候经常遇到各种各样的错误,最常见的错误就是数据带入模型之后,数据的类型不对,因此模型跑不下去,因此说,利用he ...
- Linux 命令之 linux 四剑客
Linux命令-- 四剑客 一:Linux命令 之 AWK 符号:^ 开头 $ 结尾 awk 是一种处理文本的语言,一个强大的文本分析命令! 1:提取文件中的每行的第二个 提取前文本中内容为 命令: ...
- C#MVC用ZXing.Net生成二维码/条形码
开篇:zxing.net是.net平台下编解条形码和二维码的工具. 首先创建新项目 选择MVC模板 添加一个控制器 在项目引用中的引用ZXing 进行联网下载 控制器需要引用 后台控制器 pu ...
- Selenium-浏览器兼容性测试自动化
Selenium 使浏览器兼容性测试自动化成为可能,但是在不同的浏览器上依然有细微的差别 测试浏览器的兼容性--测试你的应用程序看是否能够很好得工作在不同浏览器和操作系统之上. 测试系统功能--创建回 ...