POJ2236 Wireless Network
解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后,
进行一次for循环,进行相关调整。同时注意输入输出格式,见代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
int father[maxn], vis[maxn]; struct node{
double x, y; //此处用double
}p[maxn]; int Find(int x)
{
return father[x] == x ? x : father[x] = Find(father[x]);
} void Union(int x, int y)
{
int rootx = Find(x), rooty = Find(y);
if(rootx != rooty) father[rootx] = rooty;
return ;
} int main()
{
int n, d, k, a, b;
char ch;
scanf("%d %d", &n, &d);
memset(vis, , sizeof(vis));
for(int i = ; i <= n; i++) father[i] = i;
for(int i = ; i <= n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
while(~scanf(" %c", &ch))
{
if(ch == 'O')
{
scanf("%d", &k);
vis[k] = ;
for(int i = ; i <= n; i++)
{
if(!vis[i]) continue; //必须是已经修过的
//两点距离小于等于d,则可以合并
if(sqrt((p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y)) <= d)
Union(i, k);
}
}
else
{
scanf("%d %d", &a, &b);
//根节点相同,则表明可以连接
if(Find(a) == Find(b)) printf("SUCCESS\n");
else printf("FAIL\n");
}
}
return ;
}
POJ2236 Wireless Network的更多相关文章
- POJ2236 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: 26131 Accepted: 108 ...
- poj-2236 Wireless Network &&poj-1611 The Suspects && poj-2524 Ubiquitous Religions (基础并查集)
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由 ...
- POJ2236 Wireless Network 并查集
水题 #include<cstdio> #include<cstring> #include<queue> #include<set> #include ...
- poj2236 Wireless Network(并查集直接套模板
题目地址:http://poj.org/problem?id=2236 题目大意:n台电脑都坏了,只有距离小于d且被修好的电脑才可以互相联系,联系可传递.输入n和d,n个点的坐标x y.两个操作:O ...
- POJ2236:Wireless Network(并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 39772 Accepted: 164 ...
- D - Wireless Network
来源poj2236 An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have s ...
- 【POJ - 2236】Wireless Network (并查集)
Wireless Network 这接翻译了 Descriptions 地震发生在东南亚.ACM(亚洲合作医疗团队)已经与膝上电脑建立了无线网络,但是一次意外的余震袭击,网络中的所有计算机都被打破了. ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
随机推荐
- HDU 2084 数塔(动态规划)
数塔 http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描 ...
- PHP开发入行真功夫 三扬科技
前言与目录 PHP开发入行真功夫 前言 PHP开发入行真功夫 目录 第2章 基本语法 2.1.1 判断闰年程序 2.1.2 我们现在能做的…… 2.2.1 PHP的语言概貌 2.2.2 为我们的程 ...
- ***百度统计图表Echarts的php实现类,支持柱形图、线形图、饼形图
/** * 百度数据统计图表echart的PHP实现类 * * 原作者: * @author: chenliujin <liujin.chen@qq.com> * @since 2013- ...
- AC自动机总结
AC自动机的模板 void buildAC() { while(!q.empty()) q.pop(); q.push(); while(!q.empty()) { int x=q.front();q ...
- ArrayList,LinkedList,Vector,Stack之间的区别
一,线程安全性 Vector.Stack:线程安全 ArrayList.LinkedList:非线程安全 二,实现方式 LinkedList:双向链表 ArrayList,Vector,Stack:数 ...
- HDFS2.x之RPC流程分析
HDFS2.x之RPC流程分析 1 概述 Hadoop提供了一个统一的RPC机制来处理client-namenode, namenode-dataname,client-dataname之间的通信.R ...
- 读取本地excel发短信
package com.cmcc.zysoft.sellmanager.controller; import java.io.File; import java.io.FileInputStream; ...
- QApplication::alert 如果窗口不是活动窗口,则会向窗口显示一个警告(非常好用,效果就和TeamViewer一样)
void QApplication::alert(QWidget * widget, int msec = 0)如果窗口不是活动窗口,则会向窗口显示一个警告.警报会显示msec 毫秒.如果毫秒为零,闪 ...
- MS WORD 表格自动调整列宽,自动变漂亮,根据内容自动调整 .
在MS WORD中,当有大量的表格出现时,调整每个表格的的高和宽和大小将是一件非常累的事情,拖来拖去,非常耗时间,而且当WORD文档达到300页以上时,调整反应非常的慢,每次拖拉线后,需要等待一段时间 ...
- RAID
RAID(is short for redundant arrays of independent disks) 独立/廉价磁盘冗余阵列.基本思想:把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使 ...