Wireless Network(POJ
来源:互联网 发布:富士 打印软件 编辑:程序博客网 时间:2024/06/08 05:03
一、题目大意
地震导致电脑之间失联,现在开始修复工作。若电脑A与电脑B之间的距离小于D,则可以修复。若A与B可互联,B与C可互联,则A与C可互联。
"O p" 代表电脑p已经被修好。
"S p q"代表查询电脑p和电脑q是否可以互联。
二、题目分析
比较基础的并查集。
三、附代码
#include<iostream>#include<cstdio>#include<algorithm>#include<stack>#include<queue>#include<cstring>#include<string>#include<set>#include<cmath>#include<map>#include<sstream>using namespace std;#define inf 0x3f3f3f3ftypedef long long LL;const int maxn = 1000 + 8;struct Node{ int x,y; int par; bool mark;//表示是否修好}node[maxn];int n,d,x,y;bool Judge(int a,int b){ double disx = (node[a].x - node[b].x) * (node[a].x - node[b].x); double disy = (node[a].y - node[b].y) * (node[a].y - node[b].y); double dis = sqrt(disx + disy); return dis <= d;}int Find(int a){ while(a != node[a].par) a = node[a].par; return a;}void Unite(int x,int y){ x = Find(x); y = Find(y); if(x == y) return; node[y].par = x;}bool Same(int a,int b){ return Find(a) == Find(b);}int main(){ cin >> n >> d; for(int i = 1; i <= n; ++i){ cin >> node[i].x >> node[i].y; node[i].par = i; node[i].mark = false; } string s; while(cin >> s) { if(s == "O"){ cin >> x; node[x].mark = true; for(int i = 1; i <= n; ++i){ if(i != x && Judge(i,x) && node[i].mark){ // cout << i << " " << x << endl; Unite(i,x); } } }else if(s == "S"){ cin >> x >> y; if(Same(x,y)){ cout << "SUCCESS" << endl; }else{ cout << "FAIL" << endl; } } } return 0;}/*4 10 10 20 30 4O 1O 2O 4S 1 4O 3S 1 4*/
阅读全文
0 0
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ-2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236 - Wireless Network
- poj 2236 Wireless Network
- POJ 2236 Wireless Network
- poj 2236 wireless network
- POJ--2236--Wireless Network
- POJ-2236-Wireless Network
- poj 2236 Wireless Network
- poj 2236 Wireless Network
- POJ 2236Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- POJ 2236 Wireless Network
- python 进程间通信
- 怎么简单的理解对称加密和非对称
- iOS xcode 代码行数统计
- 条件随机场总结
- 安卓直播界面开发,自定义照相机拍照,前后摄像头切换教程加源码!
- Wireless Network(POJ
- [PKU暑课笔记] 趁机膜一发线段树和树状数组
- Binary Tree Serialization
- C# AES 加密解密
- linux python2.6 Redis报错
- Restore IP Addresses问题及解法
- fullcalendar日历控件知识点集合
- 在vbox安装Kali 2017.1
- python 截取文件和文件名