TZOJ 2415 Arctic Network(最小生成树第k小边)
描述
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小边)的更多相关文章
- [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 ...
- poj 2349 Arctic Network(最小生成树的第k大边证明)
题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部 ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
- poj 2349 Arctic Network 最小生成树,求第k大条边
题目抽象出来就是有一些告诉坐标的通信站,还有一些卫星,这些站点需要互相通信,其中拥有卫星的任意两个站可以不用发射器沟通,而所有站点的发射器要都相同,但发射距离越大成本越高. 输入的数据意思: 实例个数 ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
随机推荐
- nginx 配置文件配置
server { listen 80 ; server_name test.com www.test.com; index index.html index.php index.htm; root / ...
- 开源项目几点心得,Java架构必会几大技术点
关于学习架构,必须会的几点技术 1. java反射技术 2. xml文件处理 3. properties属性文件处理 4. 线程安全机制 5. annocation注解 ...
- ORM查询api
下面的方法都是对查询的结果进行出理:比如objects.filter.values()... 1)values(*field):返回一个可迭代的字典序列<QuerySet: [{name='小王 ...
- Unicode UTF8 UTF16 urlencode base64
Unicode:是一个字符集,每个字符对应一个唯一的unicode编码,一般是16位. UTF8是针对Unicode的编码方式,因为如果每个字符都用unicode的编码存储的话会很浪费空间,比如说as ...
- 算法练习,链表二分最大n个
import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class Bin ...
- Hibernate 再接触 树状结构设计以及学生课程成绩表的设计
1 树状结构的设计 package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax. ...
- 3D模板阴影原理
3D模板阴影原理 1:先从3dsMax中导出一个简单的场景,一个园环,球,平面. 2:园环直接面向光源,园环对球体来说是一个光线的阻挡物,园环在它上面形成阴影,同时,园环和球体对平面来说是光线的阻挡物 ...
- centos 安装mysql数据库
在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1 下载并安装MySQL官方的 Yum Re ...
- scala spark 聚类
import org.apache.spark.ml.clustering.KMeansimport org.apache.spark.ml.evaluation.ClusteringEvaluato ...
- js基础-数组及数据类型
数组也是引用类型 构造函数创建数组 Object 构造函数类型(所有类型基类) Array 构造函数类型 求幂运算符 ** 2**32-1 数组容量最大 arry.length 如果减小len ...