挺接近模板的一题 接受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. Unity游戏数据用Json保存

    (一)关于路径 unity有几个关键的路径 (1).Application.dataPath 只读路径,就是工作目录的Assets路径 (2).Application.streamingAssetsP ...

  2. SharePoint 2010 BCS - 概述

    博客地址 http://blog.csdn.net/foxdave SharePoint 2010首次引入了BCS的概念 - Business Connectivity Service,即业务连接服务 ...

  3. C++11的new concepts (move semantic)

    MoveConstructible 和MoveAssignable MoveConstructible Specifies that an instance of the type can be mo ...

  4. 解决使用IIS5.0配置的FTP服务器,客户端浏览器访问时无法获取目录列表的问题。

    我在windows xp sp3下利用iis构架了FTP服务器,允许且只允许匿名用户登陆.但刚开始配置好后,不管是使用命令行模式还是使用浏览器都发现无法访问. 于是怀疑防火墙屏蔽端口所致,果不其然,在 ...

  5. hdu 2049

    Ps:WA了无限次...简直做到崩溃..高中学的知识都忘了....这道题就是跟2048差不多.. 从N个人里选M个人,有Cmn种选法,然后就是M的错排*Cnm 代码: #include "s ...

  6. C++11 不抛异常的new operator

    在google cpp style guide里面明确指出:we don't use exceptions C++11的noexcept关键字为这种选择提供了便利. C++11以前,提及malloc和 ...

  7. python中的函数调用绑定,静态方法和类方法

    在C++的类中,有两种函数:普通成员函数和静态成员函数,差别是成员函数通过类实例调用,而静态成员函数通过类名调用.本质上,成员函数在调用的时候会默认把this指针作为第一个参数传入,而静态成员函数不需 ...

  8. Milk

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...

  9. List<T>转换为DataTable

    List<info> infos = Dal.GetInfos(); DataTable dt = new DataTable(); dt.Columns.Add("cName& ...

  10. HDU 5047

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 直到看到题解,我才知道这道题考的是什么 首先交点数是Σ(16*i),区域区分的公式是 边数+点数+1=分成 ...