Arctic Network POJ - 2349
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
Output
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的更多相关文章
- (最小生成树) Arctic Network -- POJ --2349
链接: http://poj.org/problem?id=2349 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1371 ...
- Arctic Network POJ 2349 (最小生成树思想)
Description The Department of National Defence (DND) wishes to connect several northern outposts by ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- 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 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru
Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...
- Poj(2349),最小生成树的变形
题目链接:http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total S ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
随机推荐
- [转]F# Samples 101 - Visual Studio 2010
http://code.msdn.microsoft.com/F-Samples-101-0576cb9f/sourcecode?fileId=18956&pathId=1045958806 ...
- 原型模式及php实现
原型模式: 通过复制已经存在的实例来返回新的实例,而不是新建实例,并且原型(被复制的实例)是可定制的:原型模式多用于创建复杂的或耗时的实例,这种情况下,复制一个已经存在的实例是程序运行更高效无疑是一种 ...
- svn 使用手册
版本控制器:SVN 1 开发中的实际问题 1.1 小明负责的模块就要完成了,就在即将Release之前的一瞬间,电脑突然蓝屏,硬盘光荣牺牲!几个月来的努力付之东流——需求之一:备份! 1.2 这个项目 ...
- 让px单位自动转换为rem的方法
开发工具: 编辑器:vscode; css预处理器:less;(无具体要求): 步骤: 1. vscode安装cssrem插件: 2. 修改css插件的默认配置,其默认转换p ...
- 跨库导表数据(sql)
程序员用 列子: insert into "000".tbFreeReportselect ReportCode ,ReportName ,GroupNamefrom openda ...
- 读《实战 GUI 产品的自动化测试》之:第四步,高阶技巧
转自:http://www.ibm.com/developerworks/cn/rational/r-cn-guiautotesting4/ 定义测试控件库 本系列前几篇文章对 IBM 框架做了介绍, ...
- 黑马程序员----java基础:多线程
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ---- ...
- Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图的数据操作
导航 目 录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射 下一篇:Farseer.net轻量级ORM开源 ...
- html5开发移动混合App系列1-开发环境搭建
最近公司准备开发门店收银系统,是基于IPAD的程序,决定采用基于 Ionic + Cordova + AngularJS技术混合开发模式. 准备 一台mac(安装了mac os的虚拟机也可以),nod ...
- cpio - 存取归档包中的文件
总览 (SYNOPSIS) cpio {-o|--create} [-0acvABLV] [-C bytes] [-H format] [-M message] [-O [[user@]host:]a ...