POJ A-Wireless Network
http://poj.org/problem?id=2236
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 <iostream>
#include <string.h>
using namespace std; int f[1010];
int N, d;
bool rep[1010];
int q, p, n; int st[1010];
int en[1010]; void init() {
for(int i = 1; i <= N; i ++) {
f[i] = i;
rep[i] = false;
}
} int Find(int x) {
if(f[x] != x) f[x] = Find(f[x]);
return f[x];
} void Merge(int x, int y) {
int fx = Find(x);
int fy = Find(y);
if(fx != fy)
f[fx] = fy;
} int main() {
scanf("%d%d", &N, &d);
init();
for(int i = 1; i <= N; i ++)
scanf("%d%d", &st[i], &en[i]); int f1, f2;
char op;
while(~scanf("%c", &op)) {
if(op == 'O') {
scanf("%d", &n);
rep[n] = true;
for(int i = 1; i <= N; i ++) {
if(i != n && rep[i] && (en[i] - en[n]) * (en[i] - en[n]) + (st[i] - st[n]) * (st[i] - st[n]) <= d * d) {
f1 = Find(n);
f2 = Find(i);
f[f1] = f2;
}
}
}
else if(op == 'S'){
scanf("%d%d", &q, &p);
f1 = Find(p);
f2 = Find(q); if(f1 == f2) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return 0;
}
POJ A-Wireless Network的更多相关文章
- 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 - 2336  Wireless Network
		
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
 - POJ 2236 Wireless Network(并查集)
		
传送门 Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 24513 Accepted ...
 - POJ 2236 Wireless Network (并查集)
		
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
 - POJ 2236	  Wireless Network (并查集)
		
Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...
 - poj 2236  Wireless Network 【并查集】
		
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 16832 Accepted: 706 ...
 - POJ 2236 Wireless Network [并查集+几何坐标 ]
		
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
 - [ An Ac a Day ^_^ ] [kuangbin带你飞]专题五 并查集 POJ 2236 Wireless Network
		
题意: 一次地震震坏了所有网点 现在开始修复它们 有N个点 距离为d的网点可以进行通信 O p 代表p点已经修复 S p q 代表询问p q之间是否能够通信 思路: 基础并查集 每次修复一个点重新 ...
 
随机推荐
- System.Web.UI.Page
			
mdsn:点击查看此类介绍 git: 点击查看封装方法 消息弹框,消息弹框跳转,自定义脚本信息 定义:表示一个从托管 ASP.NET Web 应用程序的服务器请求的 .aspx 文件(也称为 ...
 - ionic 命令cordova
			
安装android platform : ionic platform add android 安装一维码cordova插件 :cordova plugin add https://github.co ...
 - CSU 1216异或最大值 (0-1 trie树)
			
Description 给定一些数,求这些数中两个数的异或值最大的那个值 Input 多组数据.第一行为数字个数n,1 <= n <= 10 ^ 5.接下来n行每行一个32位有符号非负整数 ...
 - 【期望dp 质因数分解】cf1139D. Steps to One
			
有一种组合方向的考虑有没有dalao肯高抬啊? 题目大意 有一个初始为空的数组$a$,按照以下的流程进行操作: 在$1\cdots m$中等概率选出一个数$x$并添加到$a$的末尾 如果$a$中所有元 ...
 - 爬虫学习(十四)——xpath项目实践
			
import osimport timeimport urllib.requestimport urllib.parsefrom lxml import etree # 构建面向对象的代码方式clas ...
 - 对于未来学习Linux的决心书,以此为鉴
			
学习Linux的决心书 我叫曹佳佳,来自祖国的大西北甘肃庆阳,2016年大专毕业之后从事自己的专业风力发电行业工作了两年多在从事风电行业的过程中越来越感觉到自己的薪资待遇和以后的发展空间越来越小,而且 ...
 - Java高并发之线程基本操作
			
结合上一篇同步异步,这篇理解线程操作. 1.新建线程.不止thread和runnable,Callable和Future了解一下 package com.thread; import java.tex ...
 - Java数据处理
			
对于形如“(TYPE=SITA##)&&(((CTYP=FPL##)||(CTYP=CHG##)||(CTYP=CNL##)||(CTYP=DLA##)||(CTYP=DL##)||( ...
 - 【shell脚本学习-1】
			
Shell学习笔记 简介: Shell 是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个 ...
 - Triangular Sums 南阳acm122
			
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + … + n ...