【UVA 10369】 Arctic Network (最小生成树)
【题意】
南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连。任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远。 而安装有无线电设备的两个站,距离不能超过D。 D越长费用越多。
现在有s个卫星设备可以安装,还有足够多的无线电设备,求一个方案,使得费用D最少(D取决与所有用无线电通信的花费最大的那条路径)。
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
【分析】
如果没有卫星设备,那就直接最小生成树。
如果卫星设备>=2,那么可以孤立s-1个区域出来(把卫星设备放在那里,剩下一个设备放在大集团里面)
相当于树的s-1条边置为0,
那当然是最小生成树的后s-1大的边置为0咯。
krukal的过程就可以直接计算结果了。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define Maxn 510 struct node
{
int x,y;
double c;
}t[Maxn*Maxn];int len; int nx[Maxn],ny[Maxn]; void ins(int x,int y,double c)
{
t[++len].x=x;t[len].y=y;t[len].c=c;
} bool cmp(node x,node y) {return x.c<y.c;} int fa[Maxn];
int ffa(int x)
{
if(x!=fa[x]) fa[x]=ffa(fa[x]);
return fa[x];
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int s,p;
scanf("%d%d",&s,&p);
for(int i=;i<=p;i++) scanf("%d%d",&nx[i],&ny[i]);
len=;
for(int i=;i<=p;i++)
for(int j=i+;j<=p;j++)
{
double xx=(double)(nx[i]-nx[j]),yy=(double)(ny[i]-ny[j]);
ins(i,j,sqrt(xx*xx+yy*yy));
}
sort(t+,t++len,cmp);
int cnt=;
for(int i=;i<=p;i++) fa[i]=i;
if(p==s) printf("0.00\n");
else
{
for(int i=;i<=len;i++)
{
if(ffa(t[i].x)!=ffa(t[i].y))
{
fa[ffa(t[i].x)]=ffa(t[i].y);
cnt++;
if(cnt==p-s) {printf("%.2lf\n",t[i].c);break;}
}
}
} }
return ;
}
2016-11-01 16:35:05
【UVA 10369】 Arctic Network (最小生成树)的更多相关文章
- uva 10369 Arctic Network (最小生成树加丁点变形)
The Department of National Defence(DND)wishestoconnectseveral northern outposts by a wireless networ ...
- 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大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...
随机推荐
- javascript源码阅读推荐
作者:马 岩(Furzoom) (http://www.cnblogs.com/furzoom/)版权声明:本文的版权归作者与博客园共同所有.转载时请在明显地方注明本文的详细链接,未经作者同意请不要删 ...
- AWS 命令行界面 + Python 的 AWS 开发工具包 (Boto3)
安装AWS CLI $ pip install awscli 安装Boto3 $ pip install boto3 设置AWS CLI $ aws configure AWS Access Key ...
- java ssh框架入门
源码:http://pan.baidu.com/s/1hspUOKG
- VS2012 直接浏览网页时报错
VS2012 直接浏览网页时报错 "托管管道模式不能为集成" 只要在configuration文件里面添加 <system.webServer> < ...
- MongoDB 2.6.x 的安装部署
1. 下载mongodb 2.6.x版本的zip包,在D盘创建目录MongoDB,解压缩到D:\MongoDB目录. 创建数据库目录D:\MongoDB\data,接下来打开命令行窗口,切换到D:\M ...
- leetcode处女作
闲来无事[真的吗?你确定→_→ 在leetcode上刷了一道题.费时一小时,也是醉了.谨以此文,纪念我的伟大成果.[呵呵 题目是找出非排序数组中缺少的最小正整数.要求时间复杂度O(n),空间复杂度为常 ...
- poi 导入/导出 工具类
package com.holy.util; import java.io.File; import java.io.FileOutputStream; import java.io.IOExcept ...
- 前不久一个swift项目用uicollectionview 用sdwebimage 加载图片,发生内存猛增,直接闪退的情况,简单说一下解决方案。
1.首先在appdelegate方法 didFinishLaunchingWithOptions SDImageCache.sharedImageCache().maxCacheSize=1024*1 ...
- java新手笔记5 类
1.进制转换 /* 企业发放的奖金根据利润提成. 利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时, 低于10万元的部分按10%提成,高于10万元的部分,可提成7.5 ...
- 动态加载js、css 代码
一.原生js: /** * 加载js和css文件 * @param jsonData.path 前缀路径 * @param jsonData.url 需要加载的js路径或css路径 * @param ...