The Department of National Defence(DND)wishestoconnectseveral 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 inadditionhaveasatellitechannel. 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 thedistancebetweenthemdoesnot 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 (directorindirect)betweeneverypair 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个点给出坐标,点和点之间可以用无线电或者卫星通信,每个点都有无线电收发器可进行无线电通信,但是只有m个点有卫星通信功能。卫星通信的距离可以无限大,但无线电通信的距离不能超过D,超过D的部分将使通信费用增加。要使通信费用最少。

其实就是求一次最小生成树,m个点有卫星通信,那么就会有m-1条边的通信距离无限大,其实就是这m-1条边不用计算费用。而剩下的边中,找出最大边作为D值,这样剩下的所有的边都不会大于D,那么不会增加通信费用。在构建MST过程中保存下所有的边权值,然后按升序排序,除掉最后的m-1条边(也就是最大的m-1条边,这些边用卫星通信),最大的那条就是D

code:

#include <iostream>
#include <cstdio>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<memory>
using namespace std;
typedef long long LL;
#define INF 1000000
#define max_v 505
struct node
{
double x,y;
}p[];
double g[max_v][max_v];
int n,m;
void init()
{
for(int i=;i<n;i++)
for(int j=;j<n;j++)
g[i][j]=INF;
}
void prim(int s)
{
double lowcost[n];
int used[n];
for(int i=;i<n;i++)
{
lowcost[i]=g[s][i];
used[i]=;
} used[s]=;
for(int i=;i<n;i++)
{
int j=;
for(int k=;k<n;k++)
{
if(!used[k]&&lowcost[k]<lowcost[j])
j=k;
}
used[j]=;
for(int k=;k<n;k++)
{
if(!used[k]&&g[j][k]<lowcost[k])
{
lowcost[k]=g[j][k];
}
}
}
sort(lowcost+,lowcost+n+);
printf("%0.2lf\n",lowcost[n-m+]);
}
double f(int i,int j)
{
double x=p[i].x-p[j].x;
double y=p[i].y-p[j].y;
return sqrt(x*x+y*y);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
for(int i=;i<n;i++)
{
scanf("%lf %lf",&p[i].x,&p[i].y);
}
init();
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
g[i][j]=g[j][i]=f(i,j);
}
}
prim();
}
return ;
}

uva 10369 Arctic Network (最小生成树加丁点变形)的更多相关文章

  1. UVA 10369 - Arctic NetWork (求最小生成树)

    题意: 在南极有  N  个科研站,要把这些站用卫星和无线电连接起来,是的任意两个之间都能互相通信,如果其中任意的一个地方安装了卫星,那么就可以和其他安装卫星的互相通信,和距离没有关系,但是安装无线电 ...

  2. uva 10369 Arctic Network

    题意: 有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星.两个基地之间可以通过卫星交流不管它们相距多远:但是通过无线电交流,就要求它们的距离不超过D.为了方便布置, ...

  3. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

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

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

  5. TZOJ 2415 Arctic Network(最小生成树第k小边)

    描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...

  6. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

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

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

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

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

  9. poj 2349 Arctic Network 最小生成树,求第k大条边

    题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...

随机推荐

  1. [SCOI2016]背单词——trie树相关

    题目描述 Lweb 面对如山的英语单词,陷入了深深的沉思,”我怎么样才能快点学完,然后去玩三国杀呢?“.这时候睿智的凤老师从远处飘来,他送给了 Lweb 一本计划册和一大缸泡椒,他的计划册是长这样的: ...

  2. BZOJ4650: [Noi2016]优秀的拆分(hash 调和级数)

    题意 题目链接 Sol NOI的题都这么良心么.. 先交个\(n^4\)暴力 => 75 hash优化一下 => 90 然后\(90\)到\(100\)分之间至少差了\(10\)难度台阶= ...

  3. com.alibaba.fastjson.JSONObject循环给同一对象赋值会出现"$ref":"$[0]"现象问题

    1.今天定义了一个JSONObject对象,引用的com.alibaba.fastjson.JSONObject,循环给这个对象赋值出现"$ref":"$[0]" ...

  4. js 数据监听--对象的变化

    class Observer { constructor(data) { this.data = data; this.filterObj(data); } static isObject(obj) ...

  5. 基于 Web 的 Go 语言 IDE - Wide 1.5.1 发布!

    Wide 是一个基于 Web 的 Go 语言 IDE, 其目标不是彻底代替本地 IDE,而是做本地 IDE 很难做到的事情: 分享代码:类似 playground,但支持多文件并提供嵌入方式,在其他网 ...

  6. zookeeper安装和配置(单机+伪集群+集群)

    #单机模式 解压到合适目录. 进入zookeeper目录下的conf子目录, 复制zoo_sample.cfg-->zoo.cfg(如果没有data和logs就新建):tickTime=2000 ...

  7. Android ImageSpan的使用

    编辑框中加图片 代码如下: mSubjectDetailView = (TextView) findViewById(R.id.subject_detail); CharSequence text = ...

  8. 理解ASP.NET 5运行时命令:DNVM, DNX, 和DNU

    ASP.NET 5 引入了一个新型的运行时,让我们可以现场交付模式组合式构建应用程序,而不依赖于宿主机上的.NET框架.这种新模式为我们提供了命令行工具(DNVM.DNX.DNU)用于管理我们的.ne ...

  9. 数值的整数次方(C++ 和 Python 实现)

    (说明:本博客中的题目.题目详细说明及参考代码均摘自 “何海涛<剑指Offer:名企面试官精讲典型编程题>2012年”) 题目 实现函数 double Power(double base, ...

  10. BigDecimal setScale()设置无效 scale()取得的值不是setScale()设置的值

    最近查看rebate数据时,发现一个bug,主要现象是,当扣款支付宝的账号款项时,返回的是数字的金额为元,而数据库把金额存储为分,这中间要做元与分的转化,这个转化规则很简单,就是*100的,所以一开始 ...