挺接近模板的一题 接受O操作的时候扫一遍 符合条件的merge进去 done

#include <cstdio>
#include <cstring>
#include <cmath> struct Point{float x,y;};
int father[]; float distance(Point a, Point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int find(int x)
{
while(father[x] != x)
x = father[x];
return x;
} void merge(int x, int y)
{
int tx = find(x);
int ty = find(y);
if(tx != ty)
father[tx] = ty;
} int main()
{
Point p[];
int n, d;
bool open[];
//initiate
memset(open, false, sizeof open);
for(int i = ; i < ; i++)
father[i] = i;
//save cordinates
scanf("%d%d", &n, &d);
for(int i = ; i <= n; i++)
scanf("%f%f", &p[i].x, &p[i].y);
//accept operations
char tmp[];
while(scanf("%s",tmp)!=EOF)
{
if(tmp[] == 'O'){
int node;
scanf("%d", &node);
open[node] = true;
for(int i = ; i <= n; i++)
if(open[i] && i != node)
if(distance(p[i], p[node]) <= (float)d){
//printf("distance(a,b) = %f\n", distance(p[i], p[node]));
//printf("a = %d b = %d\n", node, i);
merge(node, i);
}
}
else if (tmp[] == 'S'){
int a, b;
scanf("%d%d",&a,&b);
if(find(a) == find(b))
puts("SUCCESS");
else
puts("FAIL");
}
}
return ;
}

kuangbin_UnionFind A (POJ 2236)的更多相关文章

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

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

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

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

  3. poj 2236【并查集】

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

  4. poj 2236 Wireless Network (并查集)

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

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

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

  6. Poj(2236),简单并查集

    题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...

  7. [并查集] POJ 2236 Wireless Network

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

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

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

  9. POJ 2236:Wireless Network

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

随机推荐

  1. [网络技术]VPN设置

    1.解决VPN服务器默认路由困扰 现在移动办公已经变得家常便饭,每次外出出差办公需要访问单位的内网服务器时,该怎么办呢?相信很多人都想到了VPN连接!的确,使用VPN连接, 我们可以利用现成的Inte ...

  2. public protected default private

    简单来说,如果让一个变量或者方法,只想让自己类中的访问,那么就将它们设置成private 如果你想让一个变量或者方法,本包中的类可以访问,而且子类也可访问,但是包外的缺不想让他访问.就设置成prote ...

  3. string(Integer)类的equals和==区别和联系(验证密码的时候用得到)

    “==”在八种原始数据类型中,判断的是两边的值是否相等.对于对象类型来说,判断的是内存地址,所以为true所满足的条件就是两边的引用指向同一个对象. 比如String s1 = "abcde ...

  4. C#判断IP地址是否合法函数-使用正则表达式-2个 (转)

    public bool IsCorrenctIP(string ip){ string pattrn=@"(/d{1,2}|1/d/d|2[0-4]/d|25[0-5])/.(/d{1,2} ...

  5. JQuery源码分析(二)

    立即调用表达式: 任何库与框架设计的第一个要点就是解决命名空间与变量污染的问题.jQuery就是利用了JavaScript函数作用域的特性,采用立即调用表达式包裹了自身的方法来解决这个问题. jQue ...

  6. C#泛型(二)

    <1>.泛型方法 以前文章说到用一个泛型类 SortHelper 来做一个冒泡排序的处理,下面回顾一下之前的代码: public class SortHelper<T> whe ...

  7. [转]BEHAVOUR TREE

    自从开博以来,每天都会关心一下博客的访问情况,看到一些朋友的订阅或者访问,不胜欣喜,也促使我去写一些更好的博文,来和大家分享和交流,从访问 统计来看,有相当一部分是来自于搜索引擎的流量,关键字以“行为 ...

  8. Android Listener 监听的几种写法

    Android中,View的Listener方法,在是否使用匿名类匿名对象时,有各种不同的写法. OnClickListener和其他Listener方法一样,都是View类的接口,重载实现后就能使用 ...

  9. Android 常用的常量

    常用的Android常量 1.Activity Action 字符串常量("android.intent.action."+)   描述ALL_APPS               ...

  10. C++的虚函数表

    这里的例子全部来自陈皓的C++ 虚函数表解析,经过修改的. 编译器:g++ (Ubuntu 4.9.2-10ubuntu13) 4.9.2 环境:ubuntu 15.04  64位系统(地址占8字节) ...