无线电网络

  题目大意:就是地震后,所有的电脑都坏了,现在可以修复,而且要重新连成一个网络,两台电脑之间最大连接距离为D,两台电脑可以有中继电脑,按O修复电脑,按S测试两台电脑是否有链接,如果有就输出SUCCESS,不行就FAIL

  一看到电脑,我就联想到了查并集,这一题也不例外,我们维护在距离内的查并集就可以了,具体思路不难,每一次修复都扫描所有的节点看能否连接即可

  

  1 #include <iostream>
  2 #include <functional>
  3 #include <algorithm>
  4 #include <math.h>
  5 #define MAX 1004
  6
  7 using namespace std;
  8 typedef int Position;
  9 typedef struct _set
 10 {
 11     int x;
 12     int y;
 13 }Point;
 14
 15 static Point Comp[MAX];
 16 static Position Set[MAX];
 17 static bool used[MAX];
 18 static int max_dist;
 19
 20 Position Find(Position);
 21 void Unite_Set(Position, Position);
 22 void Repaired(const int, Position);
 23 void Test(Position, Position);
 24 double Dist_Cal(Position, Position);
 25
 26 int main(void)
 27 {
 28     int n, tmp_p, tmp_x, tmp_y;
 29     char choice;
 30     while (~scanf("%d%d", &n, &max_dist))
 31     {
 32         memset(Set, -1, sizeof(Set));
 33         memset(used, 0, sizeof(used));
 34         for (int i = 1; i <= n; i++)
 35             scanf("%d%d", &Comp[i].x, &Comp[i].y);
 36         getchar();
 37         while (~scanf("%c", &choice))
 38         {
 39             if (choice == 'O')
 40             {
 41                 scanf("%d", &tmp_p);
 42                 Repaired(n, tmp_p);
 43             }
 44             else
 45             {
 46                 scanf("%d%d", &tmp_x, &tmp_y);
 47                 Test(tmp_x, tmp_y);
 48             }
 49             getchar();
 50         }
 51     }
 52     return 0;
 53 }
 54
 55 double Dist_Cal(Position i, Position j)
 56 {
 57     return sqrt((double)((Comp[i].x - Comp[j].x)*(Comp[i].x - Comp[j].x)) +
 58         (double)((Comp[i].y - Comp[j].y)*(Comp[i].y - Comp[j].y)));
 59 }
 60
 61 void Unite_Set(Position x, Position y)
 62 {
 63     Position px, py;
 64     px = Find(x); py = Find(y);
 65     if (px != py)
 66     {
 67         if (Set[px] < Set[py])//按大小求并
 68         {
 69             Set[px] += Set[py];
 70             Set[py] = px;
 71         }
 72         else
 73         {
 74             Set[py] += Set[px];
 75             Set[px] = py;
 76         }
 77     }
 78 }
 79
 80 Position Find(Position x)
 81 {
 82     if (Set[x] < 0)
 83         return x;
 84     else return Set[x] = Find(Set[x]);
 85 }
 86
 87 void Repaired(const int n, Position x)
 88 {
 89     used[x] = 1;
 90     for (int i = 1; i <= n; i++)
 91     {
 92         if (i == x || !used[i]) continue;
 93         if (Dist_Cal(x, i) <= (double)max_dist)
 94             Unite_Set(x, i);
 95     }
 96 }
 97
 98 void Test(Position x, Position y)
 99 {
100     Position px, py;
101     px = Find(x);
102     py = Find(y);
103
104     if (px == py) puts("SUCCESS");
105     else puts("FAIL");
106 }

                    

转载于:https://www.cnblogs.com/Philip-Tell-Truth/p/4931985.html

DisJSet:Wireless Network(POJ 2236)相关推荐

  1. A - Wireless Network POJ - 2236

    A - Wireless Network POJ - 2236 并查集 if (op == 'S') {scanf("%d%d", &u, &v);if(vis[u ...

  2. POJ 2236 Wireless Network 并查集

    Wireless Network 并查集 Crawling in process... Crawling failed Time Limit:10000MS     Memory Limit:6553 ...

  3. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  4. 【POJ - 2236】Wireless Network (并查集)

    题干: An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up ...

  5. [kuangbin带你飞]专题五 并查集 A - Wireless Network

    A - Wireless Network 题目链接:https://vjudge.net/contest/66964#problem/A 题目: An earthquake takes place i ...

  6. Ad Hoc Networks TOPIC TWO <Wireless Network>【Personal Notes】

    Ad Hoc Networks TOPIC TWO Wireless Network GSM: FDD+TDMA GSM network architecture 情景一:网络如何识别新用户 情景二: ...

  7. Ubuntu 18.04/20.04 安装Qualcomm Atheros QCA6174 802.11ac Wireless Network Adapter 驱动

    Ubuntu 18.04/20.04下Qualcomm Atheros QCA6174驱动安装 缘起 原因分析 查找Google 详细步骤 缘起 买了新电脑,装上Ubuntu 20.04.奈何发现wi ...

  8. POJ 2236 Wireless Network

    传送门:http://poj.org/problem?id=2236 解题思路: 利用了并查集 在操作一: 主要判断这个维修的电脑,和已经维修好的电脑的关系,如果他们的距离不大于题中限制的距离,就把他 ...

  9. POJ 2236 - Wireless Network ( 并查集 )

    题意 一个计算机网络里的计算机都坏了, 现在有两种操作, "O p"代表修复了p机器, "S p q"代表检查 p, q 两台机器是否连接( 直线距离<= ...

最新文章

  1. SQLite第八课 auth.c授权文件解析
  2. 离线安装chrome浏览器的postman插件
  3. SSM项目中怎样引入并使用Bootstrap
  4. sql decimal函数例子_leetcode题库-sql练习精讲系列--三、经典排名问题
  5. wx5 mysql起不来_mysql(四)—–mysql主从配置-wx5bd1240aa20ac的博客
  6. 每次启动项目的服务,电脑竟然乖乖的帮我打开了浏览器,100行源码揭秘!
  7. JAXB众所周知的秘密
  8. 数据结构--队列Queue--循环顺序队列
  9. 快速入门虚拟机+linux安装(附带视频)
  10. html5和html的区别是什么?学HTML5要不要学html?
  11. 转专业有什么要求吗?
  12. org.apache.catalina.loader.StandardClassLoader@1af33d6
  13. Linux账号和权限管理
  14. 服务器记事本找回文本,如何还原记事本中已删除的内容
  15. 艾美捷PEG-2000 DMG解决方案
  16. 问题解决-Visio2016和Office不能并行
  17. Dell电脑,Win10系统,插入耳机没反应或者说听筒没声音该怎么解决?
  18. 惠普HP Laser MFP 137fnw 一体机驱动
  19. N个鸡蛋放到M个篮子中
  20. 【Linux内核】Linux软中断处理机制-ksoftirqd

热门文章

  1. python爬虫库教程_Python爬虫Selenium库详细教程
  2. mysql decimal 比较大小_10 分钟掌握 MySQL 的索引查询优化技巧
  3. catboost特征重要性_一文讲解特征工程!经典外文PPT及中文解析
  4. 服务器说你注册过多,为什么我的世界服务器说此用户名已被注册我都换了很多用户了都没用 爱问知识人...
  5. java获取每月最后一天_java获取每月的最后一天实现方法
  6. putty如何登陆oracle,利用putty的SSH tunnel连接Oracle
  7. java布尔类型的调用_【Java学习笔记之八】JavaBean中布尔类型使用注意事项
  8. ttc文件linux安装,centos系统安装中文字体几种方法
  9. 备忘录怎么用红笔标注_备忘录丢失怎么找回来?教你轻松玩转备忘录
  10. python矩阵赋值提高速度_Numpy大规模矩阵运算优化加速技巧