Arctic Network
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 14977   Accepted: 4777

Description

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.

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
题意及思路:有P个坐标,将P个坐标分为S组,求所有组的生成树的最大边中的最大边。求P个坐标构成的生成树,将边由大到小排序,第S条边即为所求。
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=*;
const double INF=1.0e8;
typedef pair<double,int> P;
struct Point{
int x,y,index;
}points[];
struct Edge{
int to,next;
double cost;
}es[MAXN];
int V,E;
double dist(int x1,int y1,int x2,int y2)
{
return sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
bool comp(double a,double b)
{
return a > b;
}
int head[];
void add_edge(int u,int v,double cost)
{
es[E].to=v;
es[E].cost=cost;
es[E].next=head[u];
head[u]=E;
E++;
}
int cnt;
double res[];
double d[];
int vis[];
void prim(int s)
{
for(int i=;i<=V;i++)
{
d[i]=INF;
vis[i]=;
}
d[s]=;
cnt=;
priority_queue<P,vector<P>,greater<P> > que;
que.push(P(,s));
while(!que.empty())
{
P now=que.top();que.pop();
int v=now.second;
if(vis[v]) continue;
res[cnt++]=now.first;
vis[v]=;
for(int i=head[v];i!=-;i=es[i].next)
{
Edge e=es[i];
if(d[e.to]>e.cost)
{
d[e.to]=e.cost;
que.push(P(d[e.to],e.to));
}
}
}
} int main()
{
int T;
scanf("%d",&T);
int S,P;
while(T--)
{
scanf("%d%d",&S,&P);
memset(head,-,sizeof(head));
V=P;
E=;
for(int i=;i<P;i++)
{
scanf("%d%d",&points[i].x,&points[i].y);
points[i].index=i+;
}
for(int i=;i<P;i++)
for(int j=i+;j<P;j++)
{
int indi=points[i].index;
int indj=points[j].index;
double co=dist(points[i].x,points[i].y,points[j].x,points[j].y);
add_edge(indi,indj,co);
add_edge(indj,indi,co);
} prim();
sort(res,res+cnt,comp);
printf("%0.2lf\n",res[S-]);
} return ;
}

POJ2349(求生成树中符合题意的边)的更多相关文章

  1. poj3532求生成树中最大权与最小权只差最小的生成树+hoj1598俩个点之间的最大权与最小权只差最小的路经。

    该题是最小生成树问题变通活用,表示自己开始没有想到该算法:先将所有边按权重排序,然后枚举最小边,求最小生成树(一个简单图的最小生成树的最大权是所有生成树中最大权最小的,这个容易理解,所以每次取最小边, ...

  2. exp导出一个表中符合查询条件的数据

    原文地址:exp导出一个表中符合查询条件的数据 作者:charsi 导出一个表中的部分数据,使用QUERY参数,如下导出select * from test where object_id>50 ...

  3. js 数组 添加或删除 元素 splice 创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素 filter

    里面可以用 箭头函数 splice         删除 增加 数组 中元素 操作数组 filter 创建新数组  检查指定数组中符合条件的所有元素

  4. 【转载】 C#中使用Count方法获取List集合中符合条件的个数

    很多时候操作List集合的过程中,我们需要根据特定的查询条件,获取List集合中有多少个实体对象符合查询条件,例如一批产品的对象List集合,如果这批产品的不合格数量大于10则重点备注.在C#中可以自 ...

  5. 【转载】C#使用FirstOrDefault方法快速查找List集合中符合条件的第一个实体

    在C#的List集合的操作中,有时候我们需要根据相关条件快速从List集合中获取到第一个符合条件的实体对象,例如有个全校班级的List集合,我们需要根据班级代码快速从List集合中查找出班级信息.可以 ...

  6. 【Matlab开发】matlab删除数组中符合条件的元素与散点图绘制

    [Matlab开发]matlab删除数组中符合条件的元素与散点图绘制 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ matlab删除数组中符合条件的元素 如 ...

  7. Makefile 中符合的使用

    1. $@: 表示规则中的目标文件集.在模式规则中,如果有多个目标,那么,"$@"就是匹配于 目标中模式定义的集合 2. $^  : 所有的依赖目标的集合.以空格分隔.如果在依赖目 ...

  8. PHP使用array_filter查找二维数组中符合字段和字段值的数据集合

    1.方法: /** * 获取符合字段和字段值的数组集合 * @param array $data 待过滤数组 * @param string $field 要查找的字段 * @param $value ...

  9. POJ-2485 Highways---最小生成树中最大边

    题目链接: https://vjudge.net/problem/POJ-2485 题目大意: 求最小生成树中的最大边 思路: 是稠密图,用prim更好,但是规模不大,kruskal也可以过 #inc ...

随机推荐

  1. 深入浅出Stream和parallelStream

    https://blog.csdn.net/darrensty/article/details/79283146

  2. 【BZOJ4173】数学 欧拉函数神题

    [BZOJ4173]数学 Description Input 输入文件的第一行输入两个正整数 . Output 如题 Sample Input 5 6 Sample Output 240 HINT N ...

  3. 开发环境部署git 步骤

    1.安装完后,打开git bash.  vim .gitconfig 此文件放在用户目录,即 git bash 打开后默认位置. 2.插入以下内容,保存 [user] name = email = [ ...

  4. VS2013 自动添加头部注释 -C#开发

    在团队开发中,头部注释是必不可少的.但在开发每次新建一个类都要复制一个注释模块也很不爽,所以得想个办法让开发工具自动生成我们所需要的模板.....操作方法如下: 方法/步骤 1 找你的vs安装目录, ...

  5. (1)Web 应用是一个状态机,视图与状态是一一对应的。 (2)所有的状态,保存在一个对象里面。

    Redux 入门教程(一):基本用法 - 阮一峰的网络日志 http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_basic_u ...

  6. Hibernate load 和 Get的区别

    load和get都可以取回一个对象,难道是方法重复吗?绝对不可能,那它们到底有那些区别呢? 在http://blog.chinaunix.net/u/484/showart_1093166.html这 ...

  7. 【docker】学习笔记一:制作自己的centos6.9镜像

    前言: 最近开始研究docker,在这里做一个记录. 本来开始想用centos7系列做镜像,毕竟是最新版本的centos,但是centos7有一个严重的bug,就是正常启动的镜像不能使用systemc ...

  8. 性能优化——Web前端性能优化

    核心知识点: 1.排查网站性能瓶颈的手法:分析各个环节的日志,找出异常部分 2.Web前端:网站业务逻辑之前的部分(浏览器.图片服务.CDN) 3.优化手段 1)浏览器优化 (1)减少http请求 a ...

  9. 9patch图片

    9patch图片可直接缩放,放在drawable文件夹下就可以 右边和下边指定内容区域

  10. margin的相关属性及应用

    1.margin常见问题: ①IE6下双边距   (不推荐使用float+margin,可用padding替代) 详见<css浏览器兼容问题集锦>之4.IE6中margin双边距 ②IE6 ...