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. [Luogu1345][USACO5.4]Telecowmunication 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1345 求最小割点集的大小,直接拆点转化成最小割边.把一个点拆成出点入点,入点向出点连一条容量为1的边,其他的 ...

  2. myslq 5.7 root 默认密码

    sudo sumysqld_safe --skip-grant-tables --skip-networking & UPDATE mysql.user SET password=PASSWO ...

  3. Android(java)学习笔记197:ContentProvider使用之内容观察者02

    下面通过3个应用程序之间的交互说明一下内容观察者: 一. 如下3个应用程序为相互交互的: 二.交互逻辑图: 三.具体代码: 1.   16_数据库工程: (1)数据库帮助类BankDBOpenHelp ...

  4. OpenMP入门教程(二)

    OpenMP API概述 OpenMP由三部分组成: 编译指令(19) 运行时库程序(32) 环境变量(9) 后来的API包含同样的三个组件,只是三者的数量都有所增加. 编译器指令 OpenMP编译器 ...

  5. BASH BUILTIN COMMANDS 内建命令

    除非另外说明,这一章介绍的内建命令如果接受 - 引导的选项,那么它也接受 -- 作为参数,来指示选项的结束 : [arguments] 没有效果:这个命令除了扩展 arguments 并且作任何指定的 ...

  6. 谈谈JVM内存区域的划分

    我们知道,计算机CPU和内存的交互是最频繁的,内存是我们的高速缓存区,用户磁盘和CPU的交互,而CPU运转速度越来越快,磁盘远远跟不上CPU的读写速度,才设计了内存,用户缓冲用户IO等待导致CPU的等 ...

  7. 【转】UpdateData()函数

    一.总结UpdateData()函数 UpdateData(true);//用于将屏幕上控件中的数据交换到变量中. UpdateData(false);//用于将数据在屏幕中对应控件中显示出来. 当你 ...

  8. SQL Server错误: 0 解决方案

    1.已设置两种登录模式. 2.SQL Server配置管理器已配置好. 按Windows徽标键+R组合键,然后输入cmd. 再然后输入netsh winsock reset.接下来重启电脑,应该就可以 ...

  9. 03CSS内容背景

    CSS内容背景 设置背景颜色——background-color  插入背景图片——background-image  设置背景图片位置——background-position 设置重复背景图片—— ...

  10. IIS启用32位应用程序兼容

    针对服务器出现html和jsp页面都可以应用,但唯独asp页面打不开的一种情况 win7的IIS运行在32状态下,原因是ASP程序必须在32位下才能使用ACCESS 设置办法: 打开IIS管理器,点应 ...