题目链接:http://poj.org/problem?id=2349

思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接,那么第S大条边就是我们要找的最小的D了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 555
#define inf 1LL<<60 struct Node{
int x,y;
}node[MAXN];
double map[MAXN][MAXN];
double lowcost[MAXN];
double dist[MAXN];
bool mark[MAXN];
int n,m; double Cal(int i,int j)
{
double d1=1.0*(node[i].x-node[j].x)*(node[i].x-node[j].x);
double d2=1.0*(node[i].y-node[j].y)*(node[i].y-node[j].y);
return sqrt(d1+d2);
} int cmp(const double &p,const double &q)
{
return p>q;
} double Prim(int u0)
{
int cnt=;
memset(mark,false,sizeof(mark));
for(int i=;i<=m;i++){
lowcost[i]=map[u0][i];
}
lowcost[u0]=;
mark[u0]=true;
for(int i=;i<m;i++){
double MIN=inf;
int v=u0;
for(int j=;j<=m;j++){
if(!mark[j]&&lowcost[j]<MIN){
MIN=lowcost[j],v=j;
}
}
if(MIN==inf)break;
mark[v]=true;
dist[cnt++]=lowcost[v];
for(int k=;k<=m;k++){
if(!mark[k]&&map[v][k]<lowcost[k]){
lowcost[k]=map[v][k];
}
}
}
sort(dist,dist+cnt,cmp);
//for(int i=0;i<cnt;i++)printf("%.2lf\n",dist[i]);
return dist[n-];
} int main()
{
int _case,a,b;
scanf("%d",&_case);
while(_case--){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
for(int j=;j<=m;j++)
map[i][j]=map[j][i]=(i==j?:inf);
for(int i=;i<=m;i++){
scanf("%d%d",&node[i].x,&node[i].y);
for(int j=;j<i;j++){
map[i][j]=map[j][i]=Cal(i,j);
}
}
printf("%.2lf\n",Prim());
}
return ;
}

poj 2349(最小生成树应用)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

    链接: http://poj.org/problem?id=2349 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1371 ...

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

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

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

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

随机推荐

  1. jdk 1.6 & 1.7新特性

    jdk1.6新特性 1.Desktop类和SystemTray类 2.使用JAXB2来实现对象与XML之间的映射 3.StAX 4.使用Compiler API 5.轻量级Http Server AP ...

  2. android bluetooth UUID蓝牙查询表

    ServiceDiscoveryServerServiceClassID_UUID = '{00001000-0000-1000-8000-00805F9B34FB}' BrowseGroupDesc ...

  3. virtualbox下 ubuntu 14.04设置外网独立IP

    安装时记得选择sshserver vim /etc/network/interfaces iface eth0 inet static address YOUR IP netmask 子网掩码 get ...

  4. Objective-C 编码规范

    Objective-C 编码规范,内容来自苹果.谷歌的文档翻译,自己的编码经验和对其它资料的总结. 概要 Objective-C 是一门面向对象的动态编程语言,主要用于编写 iOS 和 Mac 应用程 ...

  5. 【iOS】iOS消息推送机制的实现

    iOS消息推送的工作机制可以简单的用下图来概括: Provider是指某个iPhone软件的Push服务器,APNS是Apple Push Notification Service的缩写,是苹果的服务 ...

  6. 点击TableView中某行进入下一级界面(Swift)

    TableView这个控件在iOS的开发中非常的常见,他可以较好的展示一个层级结构.这里主要介绍,在点击某个条目的时候,如何进行跳转的下一个界面.以下是官方的关于这个跳转如何去实现,和如何去传递数据的 ...

  7. typings的理解

    简介一些js库扩展了JavaScript的特性和语法,但是TypeScript编译器并不识别,通过typings.json配置可以辅助IDE,给出有智能的提示信息,以及重构的依据.因此需要在typin ...

  8. iTween基础之iTweenPath(自定义路径移动)

    在游戏开发中经常会用到让一个游戏对象按照指定的路线移动,iTweenPath就提供了可视化的编辑路径功能. iTweenPath 下载地址: http://download.csdn.net/deta ...

  9. DataTable分组归类

    我们在做项目的时候,经常需要根据表或DataTable中某些字段来归类,为此就写出以下方法,帮组需要的人. #region 对DataTable进行分组 + public void GroupData ...

  10. 【Valid Number】cpp

    题目: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " = ...