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. [概念理解] MVC模式和C++的实现

    [转]学习可以是一件很快乐的事,特别是当你发现以前所学的点点滴滴慢慢地能够串起来或者变成了一个环,这种感觉真好.这篇文章就这么来的. 从MVC架构开始说起吧.这两天系统了解了一下MVC架构的内容,主要 ...

  2. 理解Linux系统负荷(WDCP系统后台参数之一)

    一.查看系统负荷 如果你的网站很卡,可能是因为服务器很慢,,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行).(另外,它们在苹果 ...

  3. EasyUI触发方法、触发事件、创建对象的格式??

    创建对象 $("选择器").组件名({ 属性名 : 值, 属性名 : 值 }); 触发方法 $("选择器").组件名("方法名",参数); ...

  4. 向oracle中插入date时,持久层sql怎么写???

    public class EmpDao { public void addEmp(Emp emp) throws SQLException { QueryRunner runner = new Que ...

  5. mysql 相关博客地址

    MySQL概念学习与逐步上手操作系列(一套完整)   https://www.cnblogs.com/zlslch/category/962962.html

  6. Docker入门系列5:常见问题小结

    重启容器 再次运行容器: docker start container_id 然后 docker attach container_id 就可以继续下命令了. [编辑]命名 --name [编辑]端口 ...

  7. ADO.NET Data Service

    关于ADO.NET Entity Framework部分的内容见ADO.NET Entity Framework(1-4) http://www.cnblogs.com/foundation/arch ...

  8. Windows/Linux 环境搭建Git服务器 + vs2012集成git

    1. 下载.安装Git 我的系统是Windows 7,需要安装Git for Windows. 下载地址: http://code.google.com/p/msysgit/downloads/lis ...

  9. UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position xxx ordinal not in range(12

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't deco ...

  10. 九度OJ 1049:字符串去特定字符 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8499 解决:3860 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: 测试数据有多组,每组输入字符串s和 ...