A - Wireless Network

题目链接:https://vjudge.net/contest/66964#problem/A

题目:

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats:
1. "O p" (1 <= p <= N), which means repairing computer p.
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.

The input will not exceed 300000 lines.

Output

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

Sample Input

4 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Sample Output

FAIL
SUCCESS题意:说有n台电脑,给出n组电脑之间的关系,有关系则之间有一条线连接,后面若输入字符为O,则该台电脑与图中的电脑都建立一条线,若为S则判断后面输入的两台电脑是否有关系思路:简单并查集题
//
// Created by hy on 2019/7/21.
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=2e4+10;
int father[maxn];
int p[maxn]={0};struct Node{int x;int y;
}node[maxn];int find(int x)
{if(x==father[x])return x;return father[x]=find(father[x]);
}void merge(int x,int y)
{int fx=find(x);int fy=find(y);if(fx!=fy)father[fx]=fy;
}int main()
{int n,b;scanf("%d%d",&n,&b);for(int i=0;i<1005;i++)father[i]=i;for(int i=1;i<=n;i++)scanf("%d%d",&node[i].x,&node[i].y);char ch;int x,y;while(~scanf("%c",&ch)){if(ch=='O'){scanf("%d",&x);p[x]=1;for(int i=1;i<=n;i++){if((node[i].x-node[x].x)*(node[i].x-node[x].x)+(node[i].y-node[x].y)*(node[i].y-node[x].y)<=b*b&&p[i]==1)merge(i,x);}}if(ch=='S'){scanf("%d%d",&x,&y);int aa=find(x);int bb=find(y);if(aa==bb)printf("SUCCESS\n");elseprintf("FAIL\n");}}return 0;
}

转载于:https://www.cnblogs.com/Vampire6/p/11232843.html

[kuangbin带你飞]专题五 并查集 A - Wireless Network相关推荐

  1. [kuangbin带你飞]专题五 并查集 题解+总结

    kuangbin带你飞:点击进入新世界 总结: 本人算是初学者中的初学者,欢迎交流~ 并查集的接触过的不多,大概只有普通并查集,带权并查集,种族并查集,传说中的可持续化并查集只是听说过还没有接触,不过 ...

  2. hdu 1213 How Many Tables ([kuangbin带你飞]专题五 并查集)

    点击打开链接 C - How Many Tables Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. [kuangbin带你飞]专题五 并查集 E - 食物链 (带权并查集)

    E - 食物链 题目链接:https://vjudge.net/contest/66964#problem/E 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C ...

  4. [kuangbin带你飞]专题五查并集

    写了几个查并集得题,成功把自己写晕了 之后写下面得题(写不下去了) **poj-2912 poj 文章目录 1.POJ - 1611(模板题) 2.HDU - 1213(模板题) 3.poj2236( ...

  5. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  6. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  7. “kuangbin带你飞”专题计划——专题十四:数论基础

    写在前面 1.目前还没啥写的.开始时间:2021-05-13(其实博客上看得到该博客创建时间的) 2.上一个专题刷的是网络流(博客总结),属于第一次接触.本来想的是一周特别高效,然后一周略划水,结果是 ...

  8. (2021-07-14~)“kuangbin带你飞”专题计划——专题十三:基础计算几何

    目录 前言 参考博客 自己总结的东西: 难度判断? 题目 1.[TOYS POJ - 2318 ](解决) 2.[Toy Storage POJ - 2398 ](解决) 3.[Segments PO ...

  9. [kuangbin带你飞]专题十二 基础DP1 题解+总结

    kuangbin带你飞:点击进入新世界 总结: 简单dp,最近在做,持续更新. 文章目录 总结: 1.Max Sum Plus Plus 2.Ignatius and the Princess IV ...

最新文章

  1. 和12岁小同志搞创客开发:如何驱动各类型传感器?
  2. silverlight RadGridView总结二(转载)
  3. Mysql中使用命令行导入.sql文件新建数据库表(图文)
  4. Java并发编程—自旋锁CLHLock原理
  5. 《社交网站界面设计(原书第2版)》——3.2 注册
  6. 理解一下策略模式,工厂模式
  7. 【构造】Gym - 101411F - Figure ans Spots
  8. (转)全球3.4万亿美元ETF蓝海,我们还在末尾 且听全球第二大团队讲真经
  9. oracle mysql odbc驱动程序_用于 Oracle 的 ODBC 驱动程序
  10. 计算机不支持此接口,Windows10提示不支持此接口的解决方法
  11. 【软技能】完全写作指南
  12. 苹果计算机cpu 型号怎么看,MacBook苹果电脑怎么查看cpu型号等配置详情
  13. 2020年中国水利行业发展状况及未来发展趋势分析[图]
  14. week11作业——C - 必做题11-3
  15. 人工智能情感分析源码,垃圾短信邮箱分析
  16. 屏幕录制和视频剪辑Filmage Screen
  17. c语言常见warning的消除方法及重要性
  18. spark任务运行源码
  19. Node课程(3,2,1,8,3)
  20. Qt +百度地图+获取返回位置点

热门文章

  1. 应用Tableau、Vertica的可视化大数据分析框架
  2. 7-26 单词长度 (15 分) python实现
  3. python 知乎关系图谱_5000行python代码+可视化60W数据,告诉你知乎用户不为人知的事...
  4. 对列表中k之前和之后的元素分别进行逆序
  5. java中输入的程序_Java中输入的用法
  6. 7.1 pdo 宝塔面板php_宝塔面板PHP7.2 安装mcrypt扩展
  7. 2020.07.08_Multi-passage BERT: A Globally Normalized BERT Model for Open-domain Question Answering
  8. python matplotlib绘图显示中文
  9. 恒丰银行年报:以区块链等线上“大脑”再造业务流程
  10. 瑞士加密银行SEBA将发行B轮融资股票作为证券代币