题目大意:
给你N台电脑,从1-N。一个数字,表示两台计算机的最大通信距离,超过这个距离就无法进行通信。然后分别告诉这些电脑的坐标,接下来有两种操作,第一种O表示这点电脑修好,第二种S,表示测试这两台电脑能不能进行正常的通信

修电脑就是把这点加入到图中,S 就是判断这两个结点在不在同一个集合里,也就是是否连通

Sample Input

4 1 //n d
0 1 // x y
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4
Sample Output

FAIL
SUCCESS

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int MAXN=;
int F[MAXN] ;
int x[MAXN] ;
int y[MAXN] ;
int v[MAXN] ;
int n , d ;
int find(int x)//找x的祖先结点
{
if(F[x]==x) return x;
return F[x]=find(F[x]);
}
void bing(int u,int v)
{
int t1=find(u);
int t2=find(v);
if(t1!=t2) //这两个点不在一个集合里
F[t1]=t2; //合到一个集合里
} bool dist(int a , int b)
{
int t1 = x[a] - x[b] ;
int t2 = y[a] - y[b] ;
if(t1*t1 + t2*t2 <= d*d)
return ;
else
return ;
} int main()
{
//freopen("in.txt","r",stdin) ;
cin>>n>>d ;
int i ;
for (i = ; i<= n ; i++)
cin>>x[i]>>y[i] ;
for (i = ; i<= n ; i++)
{
F[i] = i ;
v[i] = ;
}
char c ;
int t ;
while(cin>>c)
{
if (c == 'O')
{
cin>>t ;
v[t] = ;
for (i = ; i<= n ; i++)
{
if (i != t && v[i] && dist(i,t))
bing(i,t) ;
}
}
if (c == 'S')
{
int u , v ;
cin>>u>>v ;
int t1=find(u);
int t2=find(v);
if(t1!=t2) //不连通
cout << "FAIL" << endl;
else
cout << "SUCCESS" << endl;
}
} return ;
}

poj 2236 加点 然后判断某两点是否连通的更多相关文章

  1. 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解

    不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...

  2. [并查集] POJ 2236 Wireless Network

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 25022   Accepted: 103 ...

  3. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  4. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  5. poj 2236【并查集】

    poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...

  6. POJ 2236:Wireless Network

    描述 n台电脑,如果两台电脑间的距离的d范围内,则两台电脑能够连通. 如果AB连通,BC连通,则认为AC连通. 已知电脑台数N,最大距离d,以及每个电脑的坐标.有如下两种操作: O i 表示修复编号为 ...

  7. poj 2236 Wireless Network (并查集)

    链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...

  8. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

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

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

随机推荐

  1. 【刷题】LOJ 6005 「网络流 24 题」最长递增子序列

    题目描述 给定正整数序列 \(x_1 \sim x_n\) ,以下递增子序列均为非严格递增. 计算其最长递增子序列的长度 \(s\) . 计算从给定的序列中最多可取出多少个长度为 \(s\) 的递增子 ...

  2. How to 对拍?

    对拍从数学的统计学角度来说是一个好的方法,至少能在你竞赛中帮你拿回一些分--yzr大牛pas的对拍一开始还没写过,突然想学一下对拍.那么就学吧.dp水题(搜索):https://www.luogu.o ...

  3. 循环取月的三位英语名 Jan Feb

    CultureInfo ci = new CultureInfo("en-US"); DateTime now = DateTime.Now; for (int i = 0; i ...

  4. 【bzoj2877】 Noi2012—魔幻棋盘

    http://www.lydsy.com/JudgeOnline/problem.php?id=2877 (题目链接) 题意 一个${n*m}$的矩阵,维护两个操作:给任意子矩阵${+val}$:问某 ...

  5. SpringBoot整合Swagger-ui

    SpringBoot整合Swagger-ui 引入依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...

  6. 解题:CTSC 2006 歌唱王国

    题面 概率生成函数 对于菜鸡博主来说好难啊 其一般形式为$F(x)=\sum\limits_{i=0}^∞[x==i]x_i$,第i项的系数表示离散变量x取值为i的概率 一般的两个性质:$F(1)=1 ...

  7. C# 分析 IIS 日志(Log)

    由于最近又要对 IIS日志 (Log) 分析,以便得出各个搜索引擎每日抓取的频率,所以这两天一直在尝试各个办法来分析 IIS 日志 (Log),其中尝试过:导入数据库.Log parser.Powse ...

  8. C++外观模式和组合模式

    外观模式应该是用的很多的一种模式,特别是当一个系统很复杂时,系统提供给客户的是一个简单的对外接口,而把里面复杂的结构都封装了起来.客户只需使用这些简单接口就能使用这个系统,而不需要关注内部复杂的结构. ...

  9. string::replace

    #include <string> #include <cctype> #include <algorithm> #include <iostream> ...

  10. Eclipse Neon 汉化

    官网下载的Eclipse是英文版的,对于初学者来说为了减小学习的难度,将英文版汉化是有必要的. 第一步:依次点击Eclipse菜单栏上的“Help"-->”About",查看 ...