POJ 2236 Wireless Network(并查集)
Wireless Network
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 24513 | Accepted: 10227 |
Description
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
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
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
思路
#include<stdio.h> #include<string.h> const int maxn = 1005; struct Node{ int x,y; }node[maxn]; int N,d,fa[maxn]; bool repair[maxn]; int find(int x) { int r = x; while (r != fa[r]) r = fa[r]; int i = x,j; while (i != r) { j = fa[i]; fa[i] = r; i = j; } return r; } void unite(int x,int y) { x = find(x),y = find(y); if (x != y) fa[x] = y; } bool dist(struct Node xx,struct Node yy) { return ((xx.x-yy.x)*(xx.x-yy.x)+(xx.y-yy.y)*(xx.y-yy.y)) <= d*d; } int main() { int index,index1,index2; char op[5]; memset(repair,false,sizeof(repair)); scanf("%d%d",&N,&d); for (int i = 1;i <= N;i++) { fa[i] = i; scanf("%d%d",&node[i].x,&node[i].y); } while (~scanf("%s",op)) { if (op[0] == 'O') { scanf("%d",&index); repair[index] = true; for (int i = 1;i <= N;i++) { if (i != index && repair[i] && dist(node[i],node[index])) unite(i,index); } } else if (op[0] == 'S') { scanf("%d%d",&index1,&index2); index1 = find(index1),index2 = find(index2); if (index1 == index2) printf("SUCCESS\n"); else printf("FAIL\n"); } } return 0; }
POJ 2236 Wireless Network(并查集)的更多相关文章
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- poj 2236 Wireless Network (并查集)
链接:http://poj.org/problem?id=2236 题意: 有一个计算机网络,n台计算机全部坏了,给你两种操作: 1.O x 修复第x台计算机 2.S x,y 判断两台计算机是否联通 ...
- POJ 2236 Wireless Network [并查集+几何坐标 ]
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- poj 2236:Wireless Network(并查集,提高题)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16065 Accepted: 677 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
- poj 2236 Wireless Network 【并查集】
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
随机推荐
- ASP.NET + SqlSever 大数据解决方案 PK HADOOP
半个月前看到博客园有人说.NET不行那篇文章,我只想说你们有时间去抱怨不如多写些实在的东西. 1.SQLSERVER优点和缺点? 优点:支持索引.事务.安全性以及容错性高 缺点:数据量达到100万以 ...
- .net框架中少有人知的扩展cmod
最近在利用metadata api抽取.net的原数据信息,发现了不少“坑”,也发现了不少常年用着c#的人都不知道的扩展. 说到.net原数据的可扩展性,第一个让人能想到的就是CustomAttrib ...
- .Net相关
Lucene 全文搜索 http://lucenenet.apache.org/ Memcached 分布式缓存 http://memcached.org/ selenium UI自动化测试 http ...
- get_post
各种http的请求协议: http://ymiter.iteye.com/blog/1922464 HTTP请求报文和HTTP响应报文 http://www.cnblogs.com/biyeymyhj ...
- Linux终端更改提示符
打开~/.bashrc可以看到命令提示的内容为:\u@\h\w\$ \u表示用户名,\h表示主机名,\w表示当前目录,\$表示命令提示符(普通用户$,超级用户#) 这个命令提示符有点长,很碍事,\u@ ...
- Mysql与Redis的同步实践
一.测试环境在Ubuntu kylin 14.04 64bit 已经安装Mysql.Redis.php.lib_mysqludf_json.so.Gearman. 点击这里查看测试数据库及表参考 本文 ...
- SharedPrefernces使用实例讲解
activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- Android 用代码设置Shape,corners,Gradient
网上查找资料 记录学习 int strokeWidth = 5; // 3dp 边框宽度 int roundRadius = 15; // 8dp 圆角半径 int strokeColor = Col ...
- javascript 公共方法 集合
数组去重: Array.prototype.unique1 = function () { var n = []; //一个新的临时数组 for (var i = 0; i < this.len ...
- Entity Framework在WCF中序列化的问题
问题描述 如果你在WCF中用Entity Framework来获取数据并返回实体对象,那么对下面的错误一定不陌生. 接收对 http://localhost:5115/ReService.svc 的 ...