【题意】

  南极有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 (最小生成树)的更多相关文章

  1. uva 10369 Arctic Network (最小生成树加丁点变形)

    The Department of National Defence(DND)wishestoconnectseveral northern outposts by a wireless networ ...

  2. UVA 10369 - Arctic NetWork (求最小生成树)

    题意: 在南极有  N  个科研站,要把这些站用卫星和无线电连接起来,是的任意两个之间都能互相通信,如果其中任意的一个地方安装了卫星,那么就可以和其他安装卫星的互相通信,和距离没有关系,但是安装无线电 ...

  3. uva 10369 Arctic Network

    题意: 有许多基地,每个基地都有两种收发信号的方式,一种是通过无线电收发机,另一种是通过卫星.两个基地之间可以通过卫星交流不管它们相距多远:但是通过无线电交流,就要求它们的距离不超过D.为了方便布置, ...

  4. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  5. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  6. TZOJ 2415 Arctic Network(最小生成树第k小边)

    描述 The Department of National Defence (DND) wishes to connect several northern outposts by a wireles ...

  7. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

  8. POJ 2349 Arctic Network(最小生成树+求第k大边)

    题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...

  9. poj 2349 Arctic Network(最小生成树的第k大边证明)

    题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...

  10. poj 2349 Arctic Network 最小生成树,求第k大条边

    题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...

随机推荐

  1. 通过定时监听input框来实现onkeyup事件-

    问题:因为zepto无法使用onkeyup 事件 解决方法:通过给input框绑定focus 事件,定时的去监听input的值得改变,在鼠标移出input后,清除定时器 <!DOCTYPE ht ...

  2. ios objection

    给大家介绍个不错的团队开发模块化工具objection 1. setup<这里我只介绍ios相关> rake artifact:ios cp -R build/Release-iphone ...

  3. UIWebView和UIActivityIndicatorView的结合使用

    环境:Xcode6.1 UIWebView是iOS开发中常用的一个控件,是内置的浏览器控件,我们可以用它来浏览网页,加载文档等.这篇文件将结合UIActivityIndicatorView控件制作一个 ...

  4. 不同浏览器下css 透明度的写法

    filter:alpha(opacity=90); /* IE transparent */ -moz-opacity:0.9; /* Moz + FF transparent */ opacity: ...

  5. javascript格式化指定的日期对象

    /* * 格式化Date对象为:“2015-04-17 10:20:00” * var dateObj = new Date(); */ function formartDate(dateObj){ ...

  6. 九度OJ 1373 整数中1出现的次数(从1到n整数中1出现的次数)

    题目地址:http://ac.jobdu.com/problem.php?pid=1373 题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU ...

  7. 检测 IE 版本 in Javascript

    点击打开链接http://stackoverflow.com/questions/10964966/detect-ie-version-in-javascript <!doctype html& ...

  8. 禁止 apache 开机启动

    sudo update-rc.d apache2 disable http://askubuntu.com/questions/19320/what-is-the-recommended-way-to ...

  9. linux下多线程踩过的坑(不定更新)

    1,多线程下整个进程的退出 <<APUE>>关于进程环境一章中指出了进程退出的8个条件: ... (4)最后一个线程从启动例程中返回 (5)最后一个线程调用pthread_ex ...

  10. jquery 之效果

    // jquery 之效果 .css()既可以获取值,如 .css('fontSize'), 又可以设置内置属性,既可用驼峰式,也可以用连字符版,如 .css('background-color', ...