poj 2349 Arctic Network
http://poj.org/problem?id=2349
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 12544 | Accepted: 4097 |
Description
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Input
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题目大意:有n个哨站,s个卫星频道,有卫星频道的哨站之间的距离可以忽略, 两个哨站之间只有在距离不超过D时才能联络,求D
n个哨站有n - 1条边,s个卫星频道有s - 1条边,用s - 1条边去替换哨站中的边,之后再在哨站连接的边中找最大的边
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#define INF 0x3f3f3f3f
#define max(a, b)(a > b ? a : b)
#define min(a, b)(a < b ? a : b)
#define N 510 using namespace std; struct st
{
int x, y;
} node[N]; double G[N][N], dist[N];
int n;
bool vis[N]; void Init()
{
int i, j;
memset(vis, false, sizeof(vis));
for(i = ; i < n ; i++)
{
for(j = ; j < n ; j++)
{
if(i == j)
G[i][j] = ;
G[i][j] = G[j][i] = INF;
}
}
} void prim(int s)
{
int index, i, j;
double Min;
for(i = ; i < n ; i++)
dist[i] = G[s][i];
vis[s] = true;
for(i = ; i < n ; i++)
{
Min = INF;
for(j = ; j < n ; j++)
{
if(!vis[j] && dist[j] < Min)
{
Min = dist[j];
index = j;
}
}
vis[index] = true;
for(j = ; j < n ; j++)
{
if(!vis[j] && dist[j] > G[index][j])
dist[j] = G[index][j];
}
}
} int cmp(const void *a, const void *b)
{
return *(double *)a > *(double *)b ? : -;
}//double类型快排,因为这wa了很多次 int main()
{
int i, j, s, t;
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &s, &n);
Init();
for(i = ; i < n ; i++)
scanf("%d%d", &node[i].x, &node[i].y);
for(i = ; i < n ; i++)
{
for(j = ; j < n ; j++)
{
G[i][j] = G[j][i] = sqrt((node[i].x - node[j].x) * (node[i].x - node[j].x) + (node[i].y - node[j].y) * (node[i].y - node[j].y));
}
}
prim();
qsort(dist, n, sizeof(dist[]), cmp);
printf("%.2f\n", dist[n - s]);
}
return ;
}
poj 2349 Arctic Network的更多相关文章
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- poj 2349 Arctic Network(prime)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25165 Accepted: 7751 Description The ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
- POJ 2349 Arctic Network(贪心 最小生成树)
题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...
随机推荐
- poj 1177 Picture (线段树 扫描线 离散化 矩形周长并)
题目链接 题意:给出n个矩形,每个矩形给左下 和 右上的坐标,求围成的周长的长度. 分析: 首先感谢大神的博客,最近做题经常看大神的博客:http://www.cnblogs.com/kuangbin ...
- A06_RelativeLayout的属性设置
设有两个控件one和two,以控件one为基准.由于代码比较简单就不贴了,直接上效果图. 一.第一组:将控件two放在控件one的上.下.左.右.开始.结束. android:layout_below ...
- Eclipse中设置在创建新类时自动生成注释
方法一:Eclipse中设置在创建新类时自动生成注释 windows-->preference Java-->Code Style-->Code Templates code--&g ...
- 基于XMPP的即时通信系统的建立(四)— 组件介绍
服务端 服务器 许可证 操作系统 是否支持任意客户端登录 备注 ejabberd 开源 Elang 是 支持虚拟主机和集群 Openfire Apache Java 是 Tigase GPLv3 Ja ...
- SQL复制表及表结构
复制表结构和数据SQL语句 1:复制表结构及数据到新表 select * into 目的数据库名.dbo.目的表名 from 原表名 select * into my0735home.dbo.info ...
- 实现一个简单的FTP服务器(十四)
此为一个网络编程的一个系列,后续会把内容补上...
- php linux部署相关
http://www.itbulu.com/wdcp-php55.html http://www.wdlinux.cn/wdcp/install.html http://www.yiichina.co ...
- Ejabberd源码解析前奏--配置
一.基本配置 配置文件将在你第一次启动ejabberd时加载,从该文件中获得的内容将被解析并存储到内部的ejabberd数据库中,以后的配置将从数据库加载,并且任何配置文件里的命令都会被添加到 ...
- Oracle行列互换 横表和纵表
/* 在实际使用sql工作中总会碰到将某一列的值放到标题中显示.就是总说的行列转换或者互换. 比如有如下数据: ID NAME KECHENG CHENGJI -- ---------- ------ ...
- 查询MySQL锁等待的语句
select 'Blocker' role, p.id, p.user, left(p.host, locate(':', p.host) - 1) host, tx.trx_ ...