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. 10-客户端防表单重复提交和服务器端session防表单重复提交

    /****************************************************DoFormServlet********************************** ...

  2. 一条长l的笔直的街道上有n个路灯,若这条街的起点为0,终点为l,第i个路灯坐标为ai,每盏灯可以覆盖到的最远距离为d,为了照明需求,所有灯的灯光必须覆盖整条街,但是为了省电,要是这个d最小,请找到这个最小的d。

    // ConsoleApplication3.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> ...

  3. Windows系统的Jenkins持续集成环境

    Windows系统的Jenkins持续集成环境 如题:本文将介绍如何在Windows环境下运用Jenkins部署持续集成环境.之所以写本文,是因为在最近工作当中,学习使用Jenkins时,确实遇到了一 ...

  4. Redis单台的安装部署及集群部署

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集(diff ...

  5. 如何在IntelliJ IDEA在线查看源码的API文档

    https://blog.csdn.net/IFollowRivers/article/details/81604463

  6. c++ get the pointer from the reference

    int x = 5; int& y = x; int* xp = &x; int* yp = &y; xp is equal to yp. 也就是说,直接对reference取 ...

  7. Large-scale Incremental Processing Using Distributed Transactions and Notifications

    Large-scale Incremental Processing Using Distributed Transactions and Notifications

  8. 关于String,StringBuffer与StringBuilder的区别

    String是字符串常量对象,对其进行改变时会相当影响效率,特别注意在循环中直接拼接字符串效率非常差. 如果你想改变字符串的值,更加推荐使用StringBuffer与StringBuilder两种可变 ...

  9. reduce python 的用法

    1.查看reduce 的用法 在python 命令查看 import functools help(functools) help(functools.reduce) 或者 from functool ...

  10. Qt — 子窗体操作父窗体中的方法

    父窗体与子窗体各自的代码如下: 1.  父窗体的代码: void FartherWindow::addactions() { SubWindow subwindow(this); // 把父窗体本身t ...