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 表示修复编号为 ...
随机推荐
- MapReduce数据流(二)
输入块(InputSplit):一个输入块描述了构成MapReduce程序中单个map任务的一个单元.把一个MapReduce程序应用到一个数据集上,即是指一个作业,会由几个(也可能几百个)任务组成. ...
- DetectEncoding
private Encoding DetectEncoding(ref Stream stream) { if (_pageEncoding != null) { return _pageEncodi ...
- C# 调用配置文件SQL语句 真2B!
/********************************************************************************* ** File Name : SQ ...
- IOS打开其他应用、以及被其他应用打开
1.打开其他应用 appURLStr = "cwork://app_id?title=xxx&content=xxx" [[UIApplication sharedAppl ...
- hdoj-2021
#include "stdio.h"void calculate(int number,int &a,int &b,int &c,int &d,in ...
- 2016 - 1- 22 NSURLConnetction --- POST请求
一:与上一篇博客中的GET方法类似 只不过需要多注意,如果要改变请求的类型,需要生成NSMutableURLRequest对象才可以设置请求的类型. NSURL *url = [NSURL URLW ...
- 从Wireshark监听的数据中提取需要的数据
最近,需要将wireshark监听的数据进行提取,分两步:首先,应该得出wireshark的数据包吧,在图形化界面中可以非常直观的将监听数据进行存储,但是这样需要手动操作非常麻烦,而且容易出错(随着处 ...
- ubuntu添加共享出错
早上设置一个共享目录share. 右键共享,之后系统自动安装软件samba,之后共享出错: "net usershare"返回错误 255:net usershare: canno ...
- D - Mysterious Present
这个题和求最长递增序列的题类似,为了能输出一组可行的数据,我还用了一点儿链表的知识. Description Peter decided to wish happy birthday to his f ...
- Java 集合深入理解(3):Collection
点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情有点粉,来学学 Collection 吧! 什么是集合? 集合,或者叫容器,是一个包含多个元素的对象: 集合可以对 ...