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 表示修复编号为 ...
随机推荐
- hash算法
作者:July.wuliming.pkuoliver 说明:本文分为三部分内容, 第一部分为一道百度面试题Top K算法的详解:第二部分为关于Hash表算法的详细阐述:第三部分为打造一个最快的Hash ...
- [C/C++]C/C++相关网站
1.http://en.cppreference.com What is the purpose of this site? Our goal is to provide programmers wi ...
- arguments.callee
arguments.callee在哪个函数中运行,他就代表哪个函数,一般在匿名函数中.在匿名函数中有时需要自己调用自己,但是由于是匿名函数,没有名字,所以可以用arguments.callee来代替匿 ...
- 2016 - 1 -17 GCD学习总结
一:GCD中的两个核心概念,队列与任务: 1.任务:执行什么操作.(代码块 block) 任务执行的类型分为以下两种: 1.1同步执行任务:在当前线程执行任务.不会开辟新的线程. 1.2异步执行任务: ...
- (spring-第10回【IoC基础篇】)InstantiationStrategy--实例化Bean的第三大利器
Bean的实例化整个过程如下图: : 其中,BeanDefinition加入到注册表中,并由BeanFactoryPostProcessor的实现类处理后,需要由InstantiationStrate ...
- [Java Basics] Stack, Heap, Constructor, I/O, Immutable, ClassLoader
Good about Java: friendly syntax, memory management[GC can collect unreferenced memory resources], o ...
- 学习笔记:js、css、html判断浏览器的各种版本
js.css.html判断浏览器的各种版本 (转载自:http://www.jb51.net/web/42244.html 版权归原作者所有) 利用正则表达式来判断ie浏览器版本 判断是否IE浏览器 ...
- JSOI球形空间产生器 (高斯消元)
按照朴素的列方程,可以列出n+1个n元2次方程. 将相邻的两个方程相减就可以得到n个n元1次方程,进行高斯消元就可以了. ..,..] of extended; temp,ans:..] of ext ...
- 关于IE条件注释(译)
本文翻译自此篇文章.翻译纯属业余. 许多网站为了确保他们的站点能够在不同的浏览器上有不同的显示效果而使用特征检测,一些传统的网站使用其他技术,诸如在服务器或客户端上使用脚本去检测浏览器类型.在这里我们 ...
- Disable Portrait in app
I had this problem as well as I wanted to constrain my game to only landscape mode. I put this in my ...