#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. soj98 卡牌

    题意:一共有n张牌,每张牌有三个属性ai,bi,ci.问在属性上限为A,B,C的所有牌中有多少张牌满足至少有两个属性可以完全压制(严格大于)那n张牌? n<=50W. 标程: #include& ...

  2. Mysql的数据列类型效率

    1.    能短就不要长.(磁盘I/O少一些) 比如固定 长度的CHAR数据列,定义 CHAR(40),而不是 CHAR(255); 比如MEDIUMINT代替BIGINT,数据表就小一些, 值的处理 ...

  3. webpack打包指定HTML的文件并引入指定的chunks

    1. 安装 html-webpack-plugin npm install html-webpack-plugin --save-dev 2. 在webpack.config.js中配置 const ...

  4. Android基础控件DatePicker的使用

    1.简介 DatePicker日期选择器,自带spinner和calendar两种模式,相关属性: android:calendarTextColor : 日历列表的文本的颜色 android:cal ...

  5. exiftool(-k)与gui的联合使用

    首先下载一个exiftool下载后改名字https://sno.phy.queensu.ca/~phil/exiftool/ 根据自己的操作系统选择,我需要这个 然后下载guihttp://u88.n ...

  6. 第一周课堂笔记5th

    1.      While循环机制 如何终止循环? 改变条件(根据上面的流程,只要改变条件,就会终止循环). 关键字:break. 调用系统命令:quit(),exit() 后面会讲到,不建议大家使用 ...

  7. <每日一题>题目17:super()继承相关的面试题

    class A(object): def go(self): print("go A go!") def stop(self): print("stop A stop!& ...

  8. mybatis-环境配置-基本案例-和hibernate区别

    Mybatis第一天 1.  Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了goo ...

  9. Tornado demo3 - tcpecho分析

    在这个demo中,主要是使用了Tornado中异步的TCP client和server来实现一个简单的echo效果(即客户端发送的message会从server端返回到client).代码的githu ...

  10. java 模拟简单搜索

    Java 模拟简单搜索 实体类 package org.dennisit.entity; /** * * * @version : 1.0 * * @author : 苏若年 <a href=& ...