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

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.
 

中文题意:

Description

国防部(DND)要用无线网络连接北部几个哨所。两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫星频道。
任何两个有卫星信道的哨所可以通过卫星进行通信,而不管他们的位置。同时,当两个哨所之间的距离不超过D时可以通过无线电通讯,D取决于对收发器的功率。功率越大,D也越大,但成本更高。出于采购和维修的方便,所有哨所的收发器必须是相同的;那就是说,D值对每一个哨所相同。
你的任务是确定收发器的D的最小值。每对哨所间至少要有一条通信线路(直接或间接)。

Input

输入的第一行是测试数据的数量N。
每组测试数据的第一行包含卫星频道的数量S(1 < = S < = 100)和哨所的数量P(S < P < = 500)。接下来的P行,给出以公里为单位的每个哨所的坐标(x,y)( 坐标为0到10000之间的整数)。

Output

对于每组测试数据,输出一行,输出收发器的D的最小值。精确到小数点后两位。

Sample Input


Sample Output

212.13

题意:

有P个地方,它们之间的联系方式有2种,卫星和无线电。有卫星的地方就不需要无线电了,题目输入P个地方的坐标,其中S个地方有卫星装置,没有卫星装置的只能用无线电,要使这些地方之间能通信,问最优情况下的最大无线电长度。

思路:

把P个点连接成一个最小生成树,去掉最大的S-1个长度,再求剩下最小生成树中树枝最长的长度

证明来自:https://blog.csdn.net/mengxiang000000/article/details/51482790

1、因为我们是按照剩余建造的边中最大值作为D的值来输出,那么我们一定是尽量的让D小,也就是说在入树的边中选取最大边让他尽可能小,才是我们要的结果,既然是这样,我们应该尽量将这s个城市,建造出来之后,让一些树中的边权尽可能大的边不许要建造即可。

2、至于我们要拆除的边,我们已经明确了:尽量让其边权值更大,那么我们s个城市如何分配呢?首先我们先这样来处理,使用两个点,来使得树中最大权值边不需要建造了,我们不妨拿出例子:

按照刚刚情况来看,我们选取节点1、5来使得权值为10的边不需要建造,因为这个时候S=3,所以我们还有一个点可以选,这个时候我们想要贪心的使得9这条边不需要建造,这个时候D就可以等于5了,是最理想的状态,那么是不是去掉权值为9这条边也是一定需要两个点来搞定呢?明显不需要,这个时候我们再选取一下节点4 ,使得1、2、5三个节点都相互连通了,相当于我们的图变成只有1、2、3三个节点所构成的树了,这个时候我们取得最大权值边就是D的值,为5。也就是说,有S个点,就一定能够去掉S-1条边,这个时候我们直接贪心去边即可。

代码如下:

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=1e4+;
using namespace std; struct edge_node
{
int to;
double val;
int next;
}Edge[maxn*maxn/];
int Head[maxn];
int tot; struct point_node
{
double x;
double y;
}PT[maxn]; void Add_Edge(int u,int v,double w)
{
Edge[tot].to=v;
Edge[tot].val=w;
Edge[tot].next=Head[u];
Head[u]=tot++;
} double lowval[maxn];
int pre[maxn];//记录每个点的双亲是谁
double ans[maxn];//存放最小生成树的权值
int ans_cnt;//ans数组计数器 double Prim(int n,int m,int st)//n为顶点的个数,st为最小生成树的开始顶点
{
ans_cnt=;
fill(lowval,lowval+n,INF);//不能用memset(lowval,INF,sizeof(lowval))
memset(pre,,sizeof(pre));
lowval[st]=-;
pre[st]=-;
for(int i=Head[st];i!=-;i=Edge[i].next)
{
int v=Edge[i].to;
double w=Edge[i].val;
lowval[v]=min(lowval[v],w);
pre[v]=st;
}
for(int i=;i<n-;i++)
{
double MIN=INF;
int k;
for(int i=;i<n;i++)//根据编号从0或是1开始,改i从0--n-1和1--n
{
if(lowval[i]!=-&&lowval[i]<MIN)
{
MIN=lowval[i];
k=i;
}
}
ans[ans_cnt++]=MIN;
lowval[k]=-;
for(int j=Head[k];j!=-;j=Edge[j].next)
{
int v=Edge[j].to;
double w=Edge[j].val;
if(w<lowval[v])
{
lowval[v]=w;
pre[v]=k;
}
}
}
double ANS=;
sort(ans,ans+ans_cnt);
for(int i=;i<ans_cnt-(m-);i++)
if(ans[i]>ANS)
ANS=ans[i];
return ANS;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d %d",&m,&n);
memset(Head,-,sizeof(Head));
tot=;
for(int i=;i<n;i++)
{
scanf("%lf %lf",&PT[i].x,&PT[i].y);
}
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
double x,y;
x=PT[i].x-PT[j].x;
y=PT[i].y-PT[j].y;
double val=sqrt(x*x+y*y);
Add_Edge(i,j,val);
Add_Edge(j,i,val);
}
}
printf("%.2f\n",Prim(n,m,));
}
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(最小生成树+求第k大边)

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

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

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

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

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

  5. poj 2349 Arctic Network

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

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

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

  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 Arctic Network(最小生成树中第s大的边)

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

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

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

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

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

随机推荐

  1. Ubuntu16.04 在Windows10 系统下的安装(双系统)

    楼主最近升级了一个固态+8G双通道内存条,重装了一下win10和ubuntu系统,过程中遇到一些问题,push上来供自己和大家参考.比较好用的博客教程直接贴链接. 一.win10系统 学校有正版软件许 ...

  2. BZOJ 3876 [Ahoi2014&Jsoi2014]支线剧情

    题解: 带下界的费用流 对于x->y边权为z Addedge(x,t,1,0) Addedge(s,y,1,z) Addedge(x,y,inf,0) 然后对每个点Addedge(i,1,inf ...

  3. java课程课后作业190530之用户体验评价

    每个人评价一下大家手头正在使用输入法或者搜索类的软件产品. 从用户界面.记住用户选择.短期刺激.长期使用的好处坏处.不要让用户犯简单的错误四个方面发表一篇博客. 输入法:苹果自带的输入法 用户界面:简 ...

  4. 适合初学者的10个linux命令

    转http://devopscube.com/list-of-linux-commands-every-developer-should-know/ At some point in you deve ...

  5. Maven工程配置依赖

    1.下载 安装 官网下载maven :http://maven.apache.org/download.cgi ,下载时候注意版本,IDEA旧版本如我用的2017在安装Maven时可能会报错,此时别下 ...

  6. Java中String类为什么被设计为final?

    Java中String类为什么被设计为final   首先,String是引用类型,也就是每个字符串都是一个String实例.通过源码可以看到String底层维护了一个byte数组:private f ...

  7. Linux学习-课后练习(第二章命令)20200216

  8. openstack trove mongodb配置项

    systemLog.verbosity 组件的默认日志消息详细程度级别. 详细程度级别决定MongoDB输出的信息和调试消息量. 详细级别可以在0到5之间: 0是MongoDB的默认日志详细程度级别, ...

  9. 【收藏】免费开源好看的bootstrap后台模板

    1.ace admin github:https://github.com/bopoda/acedemo:http://ace.jeka.by/ 2.CoreUI jQuery.Angular.Rea ...

  10. ADO多线程数据库查询

    {ADO查询多线程单元} unit ADOThread; interface uses Classes,StdCtrls,ADODB; type TADOThread = class(TThread) ...