#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. leetcode-137-只出现一次的数字②

    题目描述: 方法一:数学 class Solution: def singleNumber(self, nums: List[int]) -> int: return (sum(set(nums ...

  2. 关于Cadence SPB 16.6 破解的一些关键步骤

    网上搜索到的破解方法,一般来说流程都是没有什么大问题的.较详细的一个破解流程可参照: http://www.mr-wu.cn/cadence-orcad-allegro-spb-16-6-instal ...

  3. 莫烦PyTorch学习笔记(五)——分类

    import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.p ...

  4. Jtopo使用中link中文字与link平行

    修改源代码如下 //新增 a.translate(e ,f ); a.rotate(Math.atan((d.y-c.y)/(d.x-c.x))); //修改 a.fillText(this.text ...

  5. 转-VS2010常用功能使用介绍

    原文链接:http://www.jizhuomi.com/software/27.html 1.几个基础概念 在讲VS2010之前先讲下程序开发过程中的几个基本概念:源程序.目标程序和翻译程序. 源程 ...

  6. Servlet与Struts的区别

    启动: ● Servlet:无 ● Struts:配置filter,设置struts入口 创建: ● Servlet:继承HttpServlet,重写doGet与doPost方法: 添加注解或配置we ...

  7. springMVC和springBoot区别

    Spring MVC是什么?(1)Spring MVC是Spring提供的一个强大而灵活的模块式web框架.通过Dispatcher Servlet, ModelAndView 和 View Reso ...

  8. 嘴巴题8 BZOJ2318: Spoj4060 game with probability Problem

    Time Limit: 1 Sec Memory Limit: 128 MB Submit: 555 Solved: 273 [Submit][Status][Discuss] Description ...

  9. Property 'validate' does not exist on type 'Element | Element[] | Vue | Vue[]'. Property 'valid...

    使用vue-cli 3.0+Element-ui时候,调用form表单校验时候出现的问题是: Property 'validate' does not exist on type 'Element | ...

  10. sas正则式之prxparen

    sas正则式之prxparen 今天还是要继续正则式的内容,这周的内容是prxparen函数,这个函数我个人觉得特别有用,是因为他和"|"结合使用可以同时容纳很多种情况的字符串. ...