【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大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...
随机推荐
- 发布GeoServer后预览提示下载wms文件
这是因为发布的图层有中文所导致的,只需修改tomcat的server.xml文件 <Connector port="8080" protocol="HTTP/1.1 ...
- SQL错误:sql server 目录名无效
今天遇到一个错误,在网上找了半天,还有人说需要重装sql.我出错误的是网站服务器..重装影响太大了.想找一个比较不影响网站运作的办法.终于也不负我努力(啊喂!其实满百度都是可是你看不懂好吧!)找到了一 ...
- Webstorm 不识别es6 import React from ‘react’——webstorm不支持jsx语法怎么办
2016-10-31更新 webstorm不支持es6语法怎么办? webstorm不支持jsx语法怎么办? 参考:webstorm不支持jsx语法怎么办 I spent ages trying to ...
- datetimepicker 初始化只显示年
$("#overdue2").datetimepicker({ format: 'yyyy', autoclose: true, startView:4, minView:4, t ...
- Spring、struts、webwork2三者MVC的比较
http://blog.sina.com.cn/s/blog_4a69fa43010005il.html 在web应用方面,Spring有独立的MVC实现,与struts和webwork2相比毫不逊色 ...
- MFC对话框程序EDIT类控件的自动换行,垂直滚动条自动下移
1.新建一个Edit Control,将其Multiline属性设置为True,Auto HScroll属性设置False,这样就可以实现每一行填满后自动换行了. 2.再将Vetrical Scr ...
- 启动 XPs 代理
Xps代理:扩展了 1 : 运行sp_configure检查代理XPs 的 值. EXEC SP_CONFIGURE 'agent xps'查看run_value 值是否为0,如果为0:需要更改此设置 ...
- javascript 基础2第12节
1. <html> <head> <title>javascript基础</title> </head> <body> 1.Nu ...
- 04_天气查询_JAX-WS方式_服务端
[简述] WebService的Java实现共有三种方式:JAX-WS(JAX-RPC).JAXM&SAAJ.JAX-RS. JAX-WS: JAX-WS 的全称为 Java API for ...
- UVA 11584 Paritioning by Palindromes(动态规划 回文)
题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串.比如racecar本身就是回文串:fastcar只能分成7个单字母的回文串:aaadbccb最少可分成3个回文串:aaa. ...