题目大意:
给你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. IDEA 调试技巧

    转载:http://blog.csdn.net/victor_cindy1/article/details/52336983 1.这里以一个web工程为例,点击图中按钮开始运行web工程. 2.设置断 ...

  2. MySQL 主从复制详解

    读写分离的意思是,写入的时候向 a 服务器写入,而读出的时候从 b c d 甚至更多的服务器读出:这样的架构适合于读多写少的应用,最典型的就是火车购票系统,一般我们买票的时候要先查询好多次,包括车次啊 ...

  3. Spring点滴九:Spring bean的延迟初始化

    Spring bean延迟初始化: 官网API: By default, ApplicationContext implementations eagerly create and configure ...

  4. django-pure-pagination 分页插件

    官网地址:https://github.com/jamespacileo/django-pure-pagination 官网上有详细的安装和使用介绍

  5. linux系统root密码忘了怎么办 三种方法快速找回root密码

    linux root密码找回方法一 第1步:在系统进入单用户状态,直接用passwd root去更改. 第2步:用安装光盘引导系统,进行linux rescue状态,将原来/分区挂接上来,作法如下: ...

  6. 项目中经常用到的JavaScript方法

    1. js切割字符串 String.split() 注意:此方法与Array.join执行的方法是相反的. 2. js把数组中所有元素放入一个字符串 Array.join()

  7. Spark记录-Scala shell命令

    1.scala shell命令 scala> :help All commands can be abbreviated, e.g., :he instead of :help. :edit & ...

  8. bzoj千题计划253:bzoj2154: Crash的数字表格

    http://www.lydsy.com/JudgeOnline/problem.php?id=2154 #include<cstdio> #include<algorithm> ...

  9. 转载自知乎大神---this 的值到底是什么?一次说清楚

    你可能遇到过这样的 JS 面试题: var obj = { foo: function(){ console.log(this) } } var bar = obj.foo obj.foo() // ...

  10. AngularJs -- ngMessages(1.3+)

    ngMessages(1.3+) 表单和验证是AngularJS中复杂的组件之一.用AngularJS默认的方式来写,不是特别好,不简洁. 在AngualrJS1.3发布前,表单验证必须以这种方式编写 ...