链接:

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. oc 中的id类型与类型转换

    id是oc语言中一个独特的数据类型.一种通用对象类型.可以转换为任何数据类型,即id类型的变量可以存放任何数据类型的对象. 使用示例: Animal * dog = [[Dog alloc]init] ...

  2. redis-trib.rb报错:/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)

    报错如下: /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis ...

  3. Haskell语言学习笔记(27)Endo, Dual, Foldable

    Endo Monoid newtype Endo a = Endo { appEndo :: a -> a } instance Monoid (Endo a) where mempty = E ...

  4. nstall neovim on Ubuntu 16.04

    https://neovim.io/ To install NeoVim on Ubuntu, run 1 2 3 sudo add-apt-repository ppa:neovim-ppa/sta ...

  5. SQL Server:查看数据库用户权限(SQL 2005)

    1. 查看 SQL 2005 用户所属数据库角色 use yourdb go select DbRole = g.name, MemberName = u.name, MemberSID = u.si ...

  6. Hadoop slaves 没有nodeManager

    1../start-yarn.sh 后从服务器没有nodemanager 进程,并且这里没有报错 在从服务器上的日志上见: 从服务器查看日志: 查看2.8.4官方文档: https://hadoop. ...

  7. Mysql update 索引

    执行mysql update,或者delete的时候会遇到: You can't specify target table for update in FROM clause 相关的原因自不必说:下面 ...

  8. Mysql update 一个表中自己的数据

    update  table ucf, table t2 set ucf.pcid = t2.pcid where t2.name = 'liming' and t2.gid= ucf.gid and ...

  9. zoj1649-Rescue (迷宫最短路径)【bfs 优先队列】

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=649 Rescue Time Limit: 2 Seconds      Mem ...

  10. C++ auto

    auto用来声明自动变量.它是存储类型标识符,表明变量(自动)具有本地范围.块范围的变量声明(如for循环体内的变量声明)默认为auto存储类型. 好处:auto变量在离开作用域是会变程序自动释放,不 ...