#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring> using namespace std; int n, d;
double dis[][];
struct Point
{
double x, y;
}cur[]; int Tree[]; int findRoot(int x)
{
if(Tree[x] == -)
return x;
int tmp = findRoot(Tree[x]);
Tree[x] = tmp;
return tmp;
} int main()
{
scanf("%d %d", &n, &d);
for(int i = ; i <= n; ++i)
{
Tree[i] = -;
double x, y;
scanf("%lf %lf", &x, &y);
cur[i].x = x;
cur[i].y = y;
} for(int i = ; i <= n; ++i)
for(int j = i; j <= n; ++j)
{
dis[i][j] = dis[j][i] = sqrt((cur[i].x - cur[j].x)*(cur[i].x - cur[j].x)+(cur[i].y - cur[j].y)*(cur[i].y - cur[j].y));
} vector<int> rep; // repaired
char c;
while(scanf("%c", &c) != EOF)
{
if(c == 'O')
{
int t;
scanf("%d", &t);
for(int i = ; i < rep.size(); ++i)
{
if(dis[rep[i]][t] <= d)
{
/* 不能这样写,否则会导致并查集的树结构不好,
路径压缩次数过多,导致RuntimeError(栈溢出)
int ri = findRoot(rep[i]);
Tree[ri] = t;
*/ // 标准写法
int ri = findRoot(rep[i]);
int rt = findRoot(t);
if(ri != rt)
Tree[ri] = rt; }
}
rep.push_back(t); }
else if(c == 'S')
{
int t1, t2;
scanf("%d %d", &t1, &t2);
int rt1 = findRoot(t1);
int rt2 = findRoot(t2);
if(rt1 == rt2)
printf("SUCCESS\n");
else
printf("FAIL\n");
}
} return ;
}

Wireless Network POJ - 2236 (并查集)的更多相关文章

  1. POJ 2236 Wireless Network 第一次做并查集,第一次写博客

    题意是判断两台电脑是否能通讯,两台修好的电脑距离在指定距离内可直接通讯,且两台修好的电脑能通过一台修好的电脑间接通讯.代码如下: #include <iostream> #include ...

  2. Day5 - B - Wireless Network POJ - 2236

    An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...

  3. poj 2236 并查集

    并查集水题 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring& ...

  4. Wireless Network(POJ 2236)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 20724   Accepted: 871 ...

  5. A - Wireless Network POJ - 2236

    题目大意:有n台坏掉的电脑,给出每台电脑的坐标,然后每次询问输入0(字符) x,表示电脑x恢复正常,输入S x y 询问x和y是否可以联网.只要是x和y的距离小于距离d,那么就可以联网,如果有个中介c ...

  6. (并查集) Wireless Network --POJ --2236

    链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

  7. DisJSet:Wireless Network(POJ 2236)

      无线电网络 题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输 ...

  8. A - Wireless Network POJ - 2236-kuangbin带你飞

    A - Wireless Network POJ - 2236 Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 50348 ...

  9. poj 1984 并查集

    题目意思是一个图中,只有上下左右四个方向的边.给出这样的一些边, 求任意指定的2个节点之间的距离. 就是看不懂,怎么破 /* POJ 1984 并查集 */ #include <stdio.h& ...

随机推荐

  1. C++右值引用与转移语义

    std::forwad? C++11 中定义的 T&& 的推导规则为: 右值实参为右值引用,左值实参仍然为左值引用. 参考: 右值引用与转移语义

  2. postgresql计算2个日期之间工作日天数的方法

    select date_part( 'day', minus_weekend(begin_date,end_date)) from table1 where name in ('a', 'b', 'c ...

  3. 廖雪峰Java13网络编程-3其他-1HTTP编程

    1.HTTP协议: Hyper Text Transfer Protocol:超文本传输协议 基于TCP协议之上的请求/响应协议 目前使用最广泛的高级协议 * 使用浏览器浏览网页和服务器交互使用的就是 ...

  4. 并发和多线程(二)--启动和中断线程(Interrupt)的正确姿势

    启动线程: 从一个最基本的面试题开始,启动线程到底是start()还是run()? Runnable runnable = () -> System.out.println(Thread.cur ...

  5. python3-常用模块之openpyxl(1)

    1.创建工作簿 from openpyxl import Workbook # 创建excel对象 wb = Workbook() # 获取第一个sheet = wb.active # 单元格写入内容 ...

  6. Windows API 第14篇 DeleteAndRenameFile

    函数定义:BOOL DeleteAndRenameFile( LPCWSTR lpszDestFile,                                                 ...

  7. /etc/vimrc配置

    [root@guolicheng ~]# cat /etc/vimrc if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" s ...

  8. Odoo(OpenERP)配置文件详解

    [options] ; addons模块的查找路径 addons_path = E:\GreenOdoo8.0\source\openerp\addons ; 管理员主控密码(用于创建.还原和备份数据 ...

  9. JZOJ5967 常数国

    题目 像素有点低啊~ 算了凑合一下就好啦~ 题目大意 给你一个首尾相接的数列,每次对一个区间进行操作: 顺时针操作,如果当前值比vvv大,就交换.输出最后的vvv. 比赛思路 首先这题的时限这么仁慈, ...

  10. OpenCV读取RTSP视频流

    用opencv的VideoCapture读取RTSP视频流,只有opencv3.1版本可以,之前的版本都无法读取视频流.可能的原因是云平台的RTSP视频流太差,经常错码.项目最后使用的是opencv2 ...