http://poj.org/problem?id=2349

Arctic Network
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 12544   Accepted: 4097

Description

The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel. 
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

The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).

Output

For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.

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的更多相关文章

  1. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  2. 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 ...

  3. POJ 2349 Arctic Network (最小生成树)

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  4. POJ 2349 Arctic Network(最小生成树中第s大的边)

    题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...

  5. POJ 2349 Arctic Network(最小生成树+求第k大边)

    题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...

  6. poj 2349 Arctic Network(最小生成树的第k大边证明)

    题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...

  7. poj 2349 Arctic Network(prime)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25165   Accepted: 7751 Description The ...

  8. POJ 2349 Arctic Network(最小生成树,第k大边权,基础)

    题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...

  9. POJ 2349 Arctic Network(贪心 最小生成树)

    题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...

随机推荐

  1. 运行Android应用时提示ADB是否存在于指定路径问题

    打开eclipse,选择指定的Android应用工程并Run,提示: [2014-06-28 11:32:26 - LinearLayout] The connectionto adb is down ...

  2. [58 Argo]58同城开源web框架Argo搭建实践

    无意间听说58开源的消息(Long long ago),我辈欣喜异常. 一方面感谢开源同仁的辛苦劳动,另一方面也为我辈在互联网技术实践圈外的人提供了一条实践的渠道. 我迫不及待的从github上dow ...

  3. Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1

    Reference link: http://unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-nu ...

  4. HNOI2008越狱(快速幂)

    快速幂水过,贴一下模版. ; var x,y,n,m:int64; function power(num,times:int64):int64; var temp:int64; begin then ...

  5. POJ 2942 Knights of the Round Table (点双连通分量)

    题意:多个骑士要开会,3人及以上才能凑一桌,其中部分人已经互相讨厌,肯定不坐在同一桌的相邻位置,而且一桌只能奇数个人才能开台.给出多个人的互相讨厌图,要求多少人开不成会(注:会议不要求同时进行,一个人 ...

  6. 无线端不响应键盘事件(keydown,keypress,keyup)

    今天在项目时,在android手机上使用输入法的智能推荐的词的话,不会触发keyup事件,一开始想到在focus时使用一个定时器,每隔100ms检测输入框的值是否发生了改变,如果改变了就作对应的处理, ...

  7. Java [Leetcode 232]Implement Queue using Stacks

    题目描述: Implement the following operations of a queue using stacks. push(x) -- Push element x to the b ...

  8. H264 帧结构分析、帧判断

    http://blog.csdn.net/dxpqxb/article/details/7631304 H264以NALU(NAL unit)为单位来支持编码数据在基于分组交换技术网络中传输. NAL ...

  9. .NET之美——C# 中的委托和事件

    C# 中的委托和事件 文中代码在VS2005下通过,由于VS2003(.Net Framework 1.1)不支持隐式的委托变量,所以如果在一个接受委托类型的位置直接赋予方法名,在VS2003下会报错 ...

  10. java web 学习十三(使用session防止表单重复提交)

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...