链接:

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

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 13715   Accepted: 4424

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

代码:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; const int N = ;
const int INF = 0xfffffff; struct node
{
int x, y;
}s[N]; int n;
double ss[N];
double J[N][N], dist[N];
bool vis[N]; void Prim()
{
int i, j;
dist[]=;
memset(vis, , sizeof(vis));
vis[]=; for(i=; i<=n; i++)
dist[i]=J[][i]; for(i=; i<n; i++)
{
int index=;
double MIN=INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<MIN && dist[j])
{
index=j;
MIN=dist[j];
}
}
vis[index]=;
ss[index] = MIN;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]>J[index][j])
dist[j]=J[index][j];
}
}
} int main ()
{
int t;
scanf("%d", &t);
while(t--)
{
int m, i, j; scanf("%d%d", &m, &n); memset(s, , sizeof(s));
memset(ss, , sizeof(ss)); for(i=; i<=n; i++)
scanf("%d%d", &s[i].x, &s[i].y); for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
double k=sqrt(1.0*(s[i].x-s[j].x)*(s[i].x-s[j].x)+1.0*(s[i].y-s[j].y)*(s[i].y-s[j].y));
J[i][j]=J[j][i]=k;
} Prim(); sort(ss+, ss+n+); printf("%.2f\n", ss[n-m+]); }
return ;
}

(最小生成树) Arctic Network -- POJ --2349的更多相关文章

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

    Description The Department of National Defence (DND) wishes to connect several northern outposts by ...

  2. Arctic Network POJ - 2349

    The Department of National Defence (DND) wishes to connect several northern outposts by a wireless n ...

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

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

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

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

  5. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  6. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

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

  8. Poj(2349),最小生成树的变形

    题目链接:http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  9. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

随机推荐

  1. [转] #ifndef#define#endif的用法(整理) 原作者:icwk

    文件中的#ifndef 头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都include了同一个头文件.而编译时,这两个C文件要一同编译成一个可运行文件,于是问题来了, ...

  2. MySQL Installation of system tables failed!

    刚开始学习Linux,就遇到了问题. 当在RedHat下安装MySQL时提示如下错误,请高手给点指点,谢谢: rpm -vih  MySQL-server-community-5.0.96-1.rhe ...

  3. js中定时器2

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. 大型运输行业实战_day09_1_日期转换与My97DatePicker插件使用

    1.日期转换 1.1字符串类型转换成时间Date类型 /** * 给定字符串 转变 为 Date 类型 * @param date 时间 * @param format 时间格式 如:yyyy-MM- ...

  5. Python实现的常用排序方法

    1.冒泡排序,相邻位置比较大小,将比较大的(或小的)交换位置 def maopao(a):     for i in range(0,len(a)):         for j in range(0 ...

  6. 个人总结-----非贪心算法的图的m着色判断及优化问题

    1.问题描述: 对于著名的图的m着色,有两个主要的问题,一个是图的m色判定问题,一个是图的m色优化问题,描述如下. 图的m色判定问题: 给定无向连通图G和m种颜色.用这些颜色为图G的各顶点着色.问是否 ...

  7. string类小结

    要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...

  8. swift - 代码创建 pickerView 显示或隐藏横线

    import UIKit class VC1: UIViewController { fileprivate lazy var pickerV : UIPickerView = { let v = U ...

  9. Spring框架的IOC核心功能快速入门

    2. 步骤一:下载Spring框架的开发包 * 官网:http://spring.io/ * 下载地址:http://repo.springsource.org/libs-release-local/ ...

  10. 纯净版Windows7系统迅雷下载路径

    windows 7 旗舰版64位------------------- Windows 7 Ultimate (x64) - DVD (Chinese-Simplified) 详细信息 文件名     ...