挺接近模板的一题 接受O操作的时候扫一遍 符合条件的merge进去 done

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4.  
  5. struct Point{float x,y;};
  6. int father[];
  7.  
  8. float distance(Point a, Point b){
  9. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  10. }
  11.  
  12. int find(int x)
  13. {
  14. while(father[x] != x)
  15. x = father[x];
  16. return x;
  17. }
  18.  
  19. void merge(int x, int y)
  20. {
  21. int tx = find(x);
  22. int ty = find(y);
  23. if(tx != ty)
  24. father[tx] = ty;
  25. }
  26.  
  27. int main()
  28. {
  29. Point p[];
  30. int n, d;
  31. bool open[];
  32. //initiate
  33. memset(open, false, sizeof open);
  34. for(int i = ; i < ; i++)
  35. father[i] = i;
  36. //save cordinates
  37. scanf("%d%d", &n, &d);
  38. for(int i = ; i <= n; i++)
  39. scanf("%f%f", &p[i].x, &p[i].y);
  40. //accept operations
  41. char tmp[];
  42. while(scanf("%s",tmp)!=EOF)
  43. {
  44. if(tmp[] == 'O'){
  45. int node;
  46. scanf("%d", &node);
  47. open[node] = true;
  48. for(int i = ; i <= n; i++)
  49. if(open[i] && i != node)
  50. if(distance(p[i], p[node]) <= (float)d){
  51. //printf("distance(a,b) = %f\n", distance(p[i], p[node]));
  52. //printf("a = %d b = %d\n", node, i);
  53. merge(node, i);
  54. }
  55. }
  56. else if (tmp[] == 'S'){
  57. int a, b;
  58. scanf("%d%d",&a,&b);
  59. if(find(a) == find(b))
  60. puts("SUCCESS");
  61. else
  62. puts("FAIL");
  63. }
  64. }
  65. return ;
  66. }

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. MapReduce数据流(二)

    输入块(InputSplit):一个输入块描述了构成MapReduce程序中单个map任务的一个单元.把一个MapReduce程序应用到一个数据集上,即是指一个作业,会由几个(也可能几百个)任务组成. ...

  2. DetectEncoding

    private Encoding DetectEncoding(ref Stream stream) { if (_pageEncoding != null) { return _pageEncodi ...

  3. C# 调用配置文件SQL语句 真2B!

    /********************************************************************************* ** File Name : SQ ...

  4. IOS打开其他应用、以及被其他应用打开

    1.打开其他应用 appURLStr = "cwork://app_id?title=xxx&content=xxx" [[UIApplication sharedAppl ...

  5. hdoj-2021

    #include "stdio.h"void calculate(int number,int &a,int &b,int &c,int &d,in ...

  6. 2016 - 1- 22 NSURLConnetction --- POST请求

    一:与上一篇博客中的GET方法类似  只不过需要多注意,如果要改变请求的类型,需要生成NSMutableURLRequest对象才可以设置请求的类型. NSURL *url = [NSURL URLW ...

  7. 从Wireshark监听的数据中提取需要的数据

    最近,需要将wireshark监听的数据进行提取,分两步:首先,应该得出wireshark的数据包吧,在图形化界面中可以非常直观的将监听数据进行存储,但是这样需要手动操作非常麻烦,而且容易出错(随着处 ...

  8. ubuntu添加共享出错

    早上设置一个共享目录share. 右键共享,之后系统自动安装软件samba,之后共享出错: "net usershare"返回错误 255:net usershare: canno ...

  9. D - Mysterious Present

    这个题和求最长递增序列的题类似,为了能输出一组可行的数据,我还用了一点儿链表的知识. Description Peter decided to wish happy birthday to his f ...

  10. Java 集合深入理解(3):Collection

    点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 今天心情有点粉,来学学 Collection 吧! 什么是集合? 集合,或者叫容器,是一个包含多个元素的对象: 集合可以对 ...