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. VMware Workstation 不可恢复错误: (vcpu-0) vcpu-0:VERIFY vmcore/vmm/main/physMem_monitor.c:1123

    在新机器上,启动虚拟机报了个错: 使用VMware® Workstation 11.1.2 build-2780323安装MacOS系统时出现以下错误: VMware Workstation 不可恢复 ...

  2. java虚拟机之JVM生命周期

    java生命周期分为以下三部分:启动,运行,消亡. 启动.启动一个Java程序时,一个JVM实例就产生了,任何一个拥有public static void main(String[] args)函数的 ...

  3. 高质量Contrast Essay写作的结构分享

    很多留学生对于Contrast Essay写作不是很了解,拿不到高分也是常有的事,那么大家要如何彻底掌握Contrast Essay写作呢?今天小编就给同学们分享Contrast Essay写作的结构 ...

  4. jQuery中的一些方法 19.5.20课上笔记

    after() insertAfter():特定元素后面插入新的节点 before() insertBefore():特定元素前面插入新的节点 append() appendTo():向特定元素元素内 ...

  5. VS Code 配置vue开发环境

    一.插件 网上搜索vscode插件的文章,动辄十几个,其实根本用不了那么多,很多插件的作用还有重叠,电脑性能还被白白浪费.这里精简为主,每一个插件都发挥它最大的作用,并尽量说明它们的作用 Vetur ...

  6. redis主从复制原理与优化-高可用

    一 什么是主从复制 机器故障:容量瓶颈:QPS瓶颈 一主一从,一主多从 做读写分离 做数据副本 扩展数据性能 一个maskter可以有多个slave 一个slave只能有一个master 数据流向是单 ...

  7. spring_mybatis :整合

    第一步:导入相关架包(使用maven构建项目) 在pom.xml文件中导入相关依赖 1.Junit测试架包 <dependency> <groupId>junit</gr ...

  8. Codeforces 1296D - Fight with Monsters

    题目大意: n 只怪兽,每只的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b 打每只怪兽时,都是你先出手,然后你的对手出手,这样轮流攻击 如果是你给予了怪兽最后一击,你就能得到一分 你还 ...

  9. 18 12 4 SQL 的基本 语法

    数据库的基本语法 -- 数据库的操作 -- 链接数据库 mysql -uroot -p mysql -uroot -pmysql -- 退出数据库 exit/quit/ctrl+d -- sql语句最 ...

  10. java正则 读取html 获取标题/超链接/链接文本/内容

    java正则 读取html 获取标题/超链接/链接文本/内容 参考链接:http://yijianfengvip.blog.163.com/blog/static/175273432201142785 ...