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

从最小生成树中删除几条最长的边
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
#include<iomanip>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define INF 0x3f3f3f3f
#define MAXN 509 /*
最小生成树,把所有匹配的边记录下来处理
*/ struct node
{
double x, y;
}a[MAXN];
double dist(const node& a, const node& b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
struct edge
{
edge(int _a, int _b, double _c) :u(_a), v(_b), cost(_c) {}
int u, v;
double cost;
bool operator<(const edge& rhs)const
{
return cost < rhs.cost;
}
};
int pre[MAXN];
int T, k, n;
vector<edge> E;
vector<double> ans;
int find(int x)
{
if (pre[x] == -)
return x;
else
return pre[x] = find(pre[x]);
}void mix(int x, int y)
{
int fx = find(x), fy = find(y);
if (fx != fy)
pre[fx] = fy;
}
void Kruskal()
{
sort(E.begin(), E.end());
for (int i = ; i < E.size(); i++)
{
int f = E[i].u, t = E[i].v;
if (find(f) != find(t))
{
mix(f, t);
ans.push_back(E[i].cost);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
ans.clear();
E.clear();
memset(pre, -, sizeof(pre));
cin >> k >> n;
for (int i = ; i <= n; i++)
{
cin >> a[i].x >> a[i].y;
}
for (int i = ; i <= n; i++)
{
for (int j = i + ; j <= n; j++)
{
E.push_back(edge(i, j, dist(a[i], a[j])));
}
}
Kruskal();
sort(ans.begin(), ans.end());
k--;
while (k)
k--,ans.pop_back();
cout << setiosflags(ios::fixed);
cout << setprecision() << ans.back() << endl; //输出0位小数,3
}
}

Arctic Network POJ - 2349的更多相关文章

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

    链接: http://poj.org/problem?id=2349 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1371 ...

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

    Description The Department of National Defence (DND) wishes to connect several northern outposts by ...

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

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

  4. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  5. Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9557   Accepted: 3187 De ...

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

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

  7. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

  8. Poj(2349),最小生成树的变形

    题目链接:http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total S ...

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

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

随机推荐

  1. 从源码对比DefaultServeMux 与 gorilla/mux

    从源码对比DefaultServeMux 与 gorilla/mux DefaultServeMux Golang自带的net/http库中包含了DefaultServeMux方法,以此可以搭建一个稳 ...

  2. yii在Windows下安装(通过composer方式)

    Composer 安装: (Composer 不是一个包管理器,它仅仅是一个依赖管理工具.它涉及 "packages" 和 "libraries",但它在每个项 ...

  3. swift -Dynamic Dispatch

    These instructions perform dynamic lookup of class and generic methods. The class_method and super_m ...

  4. 模拟Java-Sping,实现其IOC和AOP核心

    简易的IOC框图 注解的方式实现了左边的分支,那么就剩下右边的XML分支: XmlContext:这个类是也是AbstractApplicationContext的子类,和AnnotationCont ...

  5. h5 移动端 监听软键盘弹起、收起

    前面一篇博客 h5 安卓 键盘弹起界面适配 修改webview高度提到了在adnroid中如何监听软键盘的弹起与收起,是利用的窗口的高度发生变化window.onresize事件来做突破点的,但是io ...

  6. autofs - automounter maps的格式

    描述(DESCRIPTION) automounter maps 是一系列非主映射文件或者是NIS映射(NIS maps),它们被 automounter 的主映射文件(master map)具体调用 ...

  7. chomp成功的返回值是1,chomp对参数去回车符后会改变参数的值,是传入又是传出参数。$arrow_notation = ( chomp( $unpackeing = <STDIN>) );

    44 my $unpackeing;     45 my $arrow_notation = '';     46 print "Enter  name to query, enter ex ...

  8. 用node写个简单的静态服务器

    直接上代码吧,我把它命名为 app.js, 只要在该文件所在目录下,控制台运行 node app.js 即可启动一个本地服务器了. /** * 服务器 * Author jervy * Date */ ...

  9. MFC模拟鼠标点击

    MFC 工程 把以下代码放到你想要响应的函数里面就行 CPoint pt; GetCursorPos(&pt);//获取鼠标在屏幕的当前位置 SetCursorPos(100,200);//移 ...

  10. 零基础入门学习Python(14)--字符串:各种奇葩的内置方法

    前言 这节课我们回过头来,再谈一下字符串,或许我们现在再来谈字符串,有些朋友可能觉得没必要了,甚至有些朋友就会觉得,不就是字符串吗,哥闭着眼也能写出来,那其实关于字符串还有很多你不知道的秘密哦.由于字 ...