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. 12 —— node 获取文件属性 —— 利用 自调用 闭包函数 解决 i 丢失的问题

    闭包的作用 : 保存变量 一,i 丢失的案例 var arr = ['node','vue','mysql'] for(var i=0;i<arr.length;i++){ setTimeout ...

  2. windows elasticsearch-head插件安装教程

    elasticsearch-head下载地址:https://github.com/mobz/elasticsearch-head 1.git下载 git clone git://github.com ...

  3. Thread.currentThread()和this的区别

    1. Thread.currentThread()可以获取当前线程的引用,一般都是在没有线程对象又需要获得线程信息时通过Thread.currentThread()获取当前代码段所在线程的引用. 2. ...

  4. JS隔行换色和全选的实现

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. (7)opencv图片内部的基本处理

    就是,给定我们一张图片,我们可以对图片的每一个像素的色彩进行处理 比如,我们的原图是这个样子 然后我首先将他变成灰度图(灰度图的行道是1,就是chanaual是1) 然后,我又将灰色图片的黑白进行颠倒 ...

  6. 寒假day18

    今天完成了人才动态模块的数据爬取

  7. 中后缀表达式/洛谷P1175 表达式的转换

    P1175 表达式的转换 思路:先用栈转成中缀表达式,再用栈进行计算.要输出过程,因此计算一次输出一次,但是栈没有迭代器,不好用,换成vector(可以pop_back).虽然表达式求值也可以这么做, ...

  8. ubuntu下面嘚一些常用基本命令

    1)环境变量配置: 9 ~/.bashrcor ~/.bash_profile. sudo gedit ~/.bashrc 第一种sudo vim ~/.bashrc export PYTHONPAT ...

  9. js冒泡,阻止冒泡

    js 冒泡事件 阻止冒泡 window.onload = function () { var oDiv1 = document.getElementById('div1'); var oDiv2 = ...

  10. h5-切割轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...