挺接近模板的一题 接受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. Core Text概述

    本文是我翻译的苹果官方文档<Core Text Overview> Core Text框架是高级的底层文字布局和处理字体的技术.它在Mac OS X v10.5 and iOS 3.2开始 ...

  2. VS2013开发Android App 环境搭建

    下载并安装vs2013,(安装时发现多了with blend,百度后有人说是设计师用版本,这是不对的,害我花费不少时间查找程序员用版本).我安装的是Microsoft Visual Studio Ul ...

  3. 全球著名的渗透测试Linux简介

    注:如发现链接无法打开,请尝试代理登录链接 1. Kali Linux Kali Linux是基于Debian的Linux发行版, 设计用于数字取证和渗透测试.由Offensive Security ...

  4. 过期邮件替换SQL

  5. IOS 作业项目 TableView两个section中cell置顶功能实现

    点击cell会置顶,其他的下移

  6. CentOS 7.0禁用iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. firewall: systemctl start firewalld.service#启动firewal ...

  7. HDU 1052

    http://acm.hdu.edu.cn/showproblem.php?pid=1052 田忌赛马本质就是一个贪心 res表示田忌的胜利场次 1.田忌最快马快于王的最快马,两个最快马比,res++ ...

  8. Inno Setup使用上的几个问题

    Inno Setup使用上的几个问题 分类: Install Setup 2013-02-02 15:48 1781人阅读 评论(0) 收藏 举报 Inno Setup使用上的几个问题: [问题一:I ...

  9. HDU 4819 Mosaic(13年长春现场 二维线段树)

    HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...

  10. iis6.0+.net 4.0 +mvc 404错误

    ps: 在iis中重新注册.net framework命令cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i 1 ...