kuangbin_UnionFind A (POJ 2236)
挺接近模板的一题 接受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)的更多相关文章
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- 【并查集】模板 + 【HDU 1213、HDU 1232、POJ 2236、POJ 1703】例题详解
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network ...
- poj 2236【并查集】
poj 2236 Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical t ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- (并查集) Wireless Network --POJ --2236
链接: http://poj.org/problem?id=2236 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- Poj(2236),简单并查集
题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
- POJ 2236:Wireless Network
描述 n台电脑,如果两台电脑间的距离的d范围内,则两台电脑能够连通. 如果AB连通,BC连通,则认为AC连通. 已知电脑台数N,最大距离d,以及每个电脑的坐标.有如下两种操作: O i 表示修复编号为 ...
随机推荐
- iOS中属性Property的常用关键字的使用说明
属性关键字的作用 现在我们iOS开发中,基本都是使用ARC(自动引用计数)技术,来编写我们的代码.因此在属性property中我们经常使用的关键字有strong,weak,assign,copy,no ...
- Oracle之ROW_NUMBER() OVER函数
语法:ROW_NUMBER() OVER(ORDER BY COLUMN) 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的select ACD_ID,ROW_NUMBE ...
- 模拟http或https请求,实现ssl下的bugzilla登录、新增BUG,保持会话以及处理token
1.增加相应httpclient 需要的jar包到工程,如果是maven工程请在pom.xml增加以下配置即可: <dependency> <groupId>org.apach ...
- (spring-第14回【IoC基础篇】)国际化信息
国际化又称为本地化. 当你把手机的language由中文切换到英文时,你的微信也相应改用英语,这就是i18n国际化.一般来说,应用软件提供一套不同语言的资源文件,放到特定目录中,应用根据不同语言的操作 ...
- error: Apostrophe not preceded by \
解决方案为:在编译出错提示中找到相关的string.xml文档,在string标签中的字符串含有单引号(')前面,加上反斜杠(\)转义即可.
- Map写入的顺序 输出地顺序ZT
偶然间 发现hashmap遍历的结果不是放入的顺序 为了项目某个功能更人性话 思考了半天还是不知道如何下手 因为有种种条件限制 后来 无意中发现 java.util.LinkedHashMap< ...
- Python行和缩进
Python缩进和冒号 对于Python而言代码缩进是一种语法,Python没有像其他语言一样采用{}或者begin...end分隔代码块,而是采用代码缩进和冒号来区分代码之间的层次. 缩进的空白数量 ...
- UVA1476 三分法
单峰函数(即先递增后递减,有极大值的函数),都可以用三分法来求 #include <iostream> #include <cmath> #include <cstdio ...
- ERP通用存储过程封装(三)
一:解释 SQL Server提供了一种方法:可以将一些预先编译的SQL语句集中起来由SQL Server数据库服务器来完成以实现某个任务,这就是存储过程.存储过程常驻在SQL Server ...
- 有意义的命名 Meaningful names
名副其实 use intention-revealing names 变量.函数或类的名称应该已经答复了所有的大问题.它该告诉你,他为什么会存在,他做什么事,应该怎么用.我们应该选择都是致命了计量对象 ...