POJ 2236 Wireless Network
来源:互联网 发布:棉麻旗袍 知乎专栏 编辑:程序博客网 时间:2024/05/22 10:55
本题的关键点在与,给定一个修复好的u,谁是和它连通的呢? 答案需要遍历全部的n,找出存在于并查集里的i,并且 距离(i, u) <= d。注意这里的u可能本来就已经修好,所以只需要find(i) == find(u) 就可以满足条件.
/*********************************************** * Author: fisty * Created Time: 2015/2/26 15:48:34 * File Name : A.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 1010int n, d;int vis[MAX_N];struct Point{ int x; int y;}p[MAX_N];int dist(int i, int j){ Point a = p[i]; Point b = p[j]; return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}int par[MAX_N];void init(){ for(int i = 1;i <= n; i++){ par[i] = i; }}int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]);}void unio(int x, int y){ x = find(x); y = find(y); par[x] = y;}int main() { //freopen("in.cpp", "r", stdin); //cin.tie(0); //ios::sync_with_stdio(false); cin >> n >> d; Memset(vis, 0); FOR(i, 1, n+1){ cin >> p[i].x >> p[i].y; } init(); char s[10]; while(scanf("%s", s) != EOF){ if(s[0] == 'O'){ int u; cin >> u; if(!vis[u]){ vis[u] = 1; int a = find(u); for(int i = 1;i <= n; i++){ if(vis[i] && i != u && (find(i) == a || dist(i, u) <= d*d)) unio(i, u); } } }else{ int u, v; cin >> u >> v; if(vis[u] && vis[v]){ if(find(u) == find(v)){ cout << "SUCCESS" << endl; }else{ cout << "FAIL" << endl; } }else cout << "FAIL" << endl; } } return 0;}
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
- Linux线程私有数据
- [Cocos2d塔防游戏开发]Cocos2dx-3.X完成塔防游戏《王国保卫战》--简介+代码+资源
- 设置EXCEL表某列的宽度
- 数论专题小结:素数筛法
- rails时间转换
- POJ 2236 Wireless Network
- tomcat7 设置用户名和密码 roles设置内容与以往的不同
- iOS学习4:UITextView的用法及技巧(ios7下光标bug解决方案)
- android培训、java培训、java学习型技
- PAT5-08. 迷你搜索引擎
- C# 反射属性值和遍历属性名
- Linux命令整理之七:scp
- pl/sql环境变量设置
- 写一篇文章试试