描述

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.

输入

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).

输出

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.

样例输入

1
2 4
0 100
0 300
0 600
150 750

样例输出

212.13

题意

二维平面给你p个点的图,问你形成最多s个连通块使所有边的最大值最小,并输出

题解

很容易想到最小生成树,每连一条边就少一个连通块,当我们最后形成s个连通块时找出所有边的最大值就是最小值

Kruskal算法恰好是按边大小排序,所以答案就是要我们从大到小输出第cnt-s+1条边

代码

 #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std; int s,p,F[];
struct edge
{
int u,v;
double w;
}edges[];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int Find(int x)
{
return F[x]==x?x:F[x]=Find(F[x]);
}
int tot=;
void Kruskal()
{
for(int i=;i<=p;i++)F[i]=i;
sort(edges,edges+tot,cmp);
int cnt=;
double D[];
for(int i=;i<tot;i++)
{
int fu=Find(edges[i].u);
int fv=Find(edges[i].v);
double fw=edges[i].w;
if(fu!=fv)
{
cnt++;
F[fu]=fv;
D[cnt]=fw;
if(cnt==p-)break;
}
}
if(s>=p)printf("0.00\n");
else printf("%.2f\n",D[cnt-s+]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
tot=;
int x[],y[];
scanf("%d%d",&s,&p);
for(int i=;i<=p;i++)
{
scanf("%d%d",&x[i],&y[i]);
for(int j=;j<=i;j++)
{
double dis=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
edges[tot].u=i;
edges[tot].v=j;
edges[tot++].w=dis;
}
} Kruskal();
}
return ;
}

TZOJ 2415 Arctic Network(最小生成树第k小边)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. poj2349 Arctic Network - 最小生成树

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

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

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  8. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

  9. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

随机推荐

  1. 什么是ThreadLocal

    当使用ThreadLocal维护变量时,ThreadLocal为每个使用该变量的线程提供独立的变量副本,所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本.ThreadLocal ...

  2. python_03 各种运算符

    1.算数运算 2.比较运算 3.赋值运算 4.逻辑运算 先计算括号中表达式 计算顺序:and,or,not在一个表达式中从前到后计算, 若and前一个元素为false则立刻返回为False,不计算后面 ...

  3. springboot 停止

    因springboot内嵌tomcat或jetty使得我们没法去操作服务: 因此,常常是服务起来后,要重启时会端口占用,我们只能无情的kill掉端口. 不过spring也设置有配置停止的请求: App ...

  4. UI5-学习篇-3-Local SAP WEB IDE下载

    1.下载地址 https://tools.hana.ondemand.com/#sapui5 有两个版本,针对各自系统环境选择对应的个人版本下载后解压. 个人版:个人试用 生产版:在云平台SCP付费订 ...

  5. JSdom操作内容,样式,属性

    <p> JavaScript 能够直接写入 HTML 输出流中: </p> <script> document.write("<h1>This ...

  6. css样式表1

    1内联样式表 和html联合使用,控制精确,但是可重用性差,冗余多. <p style="font-size:14px;"></p> <div sty ...

  7. UNITY2018 真机开启deepprofiling的操作

    手机上运行游戏并开启deepprofiling的命令如下 命令一:adb shell am start -n com.szyh.YHP1.kaopu/com.szyh.YHP1.kaopu.MainA ...

  8. Java IO流学习总结二:File

    Java File类的功能非常强大,利用java基本上可以对文件进行所有操作.首先来看File类的构造函数的源码 /** * Internal constructor for already-norm ...

  9. linux内核中的const成员是否可以修改?

    本文的基础知识:由于前半部分内容是转的,且不知道原文出处,没法给出原文地址,大家自行百度 const的实现机制 const究竟是如何实现的呢?对于声明为const的内置类型,例如int,short,l ...

  10. (Java)怎么去掉字符串数组中重复的值?

    String fdbs = "WXB,WXA,FDA,WXB"; String[] str = fdbs.split(","); Set set = new H ...