uva 10369 Arctic Network (最小生成树加丁点变形)
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 (最小生成树加丁点变形)的更多相关文章
- UVA 10369 - Arctic NetWork (求最小生成树)
题意: 在南极有 N 个科研站,要把这些站用卫星和无线电连接起来,是的任意两个之间都能互相通信,如果其中任意的一个地方安装了卫星,那么就可以和其他安装卫星的互相通信,和距离没有关系,但是安装无线电 ...
- uva 10369 Arctic Network
题意: 有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星.两个基地之间可以通过卫星交流不管它们相距多远:但是通过无线电交流,就要求它们的距离不超过D.为了方便布置, ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- TZOJ 2415 Arctic Network(最小生成树第k小边)
描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- poj 2349 Arctic Network 最小生成树,求第k大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...
随机推荐
- qt5.6.3下使用firebird
有人把firebird比作数据库界的瑞士军刀,想学习一下其在QT5.6中的使用,于是便开始了一场自己挖坑,自己埋的旅程. 环境说明:win7 64位+QT5.6 mingw4.9 32位(好像官网上也 ...
- Maven学习总结(四):更改maven的编码格式方式
安装系统之后,一般中文系统默认字符集是GBK.我们安装的软件一般都继承使用操作系统的默认字符集.所以当在中文XP或者win7系统开发,在使用maven(mvn compile)编译项目的时候,就会出现 ...
- Html5 填表 表单(二) input type 各种输入, 各种用户选择,上传等等泛输入用户交互
<input> 无限制输入 type 限制输入 type = 如下类型 type 后还可以跟一些属性: 如<input type=text max ...
- Drupal7安装注意事项
1.在php.ini中将max_execution_time = 2400,memory_limit = 256M
- 【javascript】javascript设计模式之工厂模式
1.要解决的问题 2.如何实现 3.与构造函数的区别 4.总结 1.要解决的问题 工厂模式通常用于重复创建相似对象,提供动态创建对象的接口. 2.工厂模式最为设计模式中构造模式之一,通常在类或类的静态 ...
- 根据HTML5 获取当前位置的经纬度【百度地图】【高德地图】
是想让地图的定位用户位置更准确一些. 查看了介绍: http://www.w3school.com.cn/html5/html_5_geolocation.asp 看介绍中拿数据挺简单. <!D ...
- LeetCode赛题515----Find Largest Element in Each Row
问题描述 You need to find the largest element in each row of a Binary Tree. Example: Input: 1 / \ 2 3 / ...
- 微信小程序-03-小程序开发框架
微信小程序-03-小程序开发框架 官方文档: https://developers.weixin.qq.com/miniprogram/dev/framework/MINA.html 小程序开发框架 ...
- android红米等关于读取本地文件夹图片获取路径的问题的解决
在Android开发中,有从本地文件夹中读取图片的功能,使用一下代码打开图片选择列表: Intent intent = new Intent(); intent.setAction(Intent. ...
- Vue.js双向绑定原理
Vue.js最核心的功能有两个,一个是响应式的数据绑定系统,另一个是组件系统.本文仅仅探究双向绑定是怎样实现的.先讲涉及的知识点,再用简化的代码实现一个简单的hello world示例. 一.访问器属 ...