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 题 ...
随机推荐
- Oracle本地动态 SQL
本地动态 SQL 首先我们应该了解什么是动态 SQL,在 Oracle数据库开发 PL/SQL块中我们使用的 SQL 分为:静态 SQL语句和动态 SQL语句.所谓静态 SQL指在 PL/SQL块中使 ...
- 前台js获得json数据
$.ajax({ type:"post", url:"testAction.action", data:{ classId:classId }, success ...
- 学JAVA第二十三天,List类型和Set类型
数组,是我们最常用的,但是有时候,我们要用数组,但是又不知道数组的类的长度的时候, 我们java就有一个很好用的工具Collection,这都是java的爸爸的用心良苦,Collection中包含Li ...
- [BZOJ1008][HNOI2008]越狱 组合数学
http://www.lydsy.com/JudgeOnline/problem.php?id=1008 正着直接算有点难,我们考虑反着来,用全集减补集. 总的方案数为$m^n$.第一个人有$m$种可 ...
- ReactJS-2-props vs state
rops理解: 大多数组件都可以在创建的时候被不同的参数定制化,这些不同的参数就叫做props.props的流向是父组件到子组件. 子组件Comment,是一条评论组件,父组件CommentList, ...
- 原生开发之css样式问题(持续更新)
·移动端开发将div高度设置为设备高度 div{ Height:100vh; } · select选择器文字设置: /*select文字右对齐*/ select{ direction: rtl; } ...
- Windows下使用JMeter
简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试C/S结构的软件(例如web应用程序).它可以被用来测试包括基于静态和动态资源程序的性能,例如静态文件,Java Ser ...
- UI动画效果
UI界面的动画效果总结 方式1:头尾式 //开始动画 [UIView beginAnimations:nil context:nil]; //设置动画时间 [UIView setAnimationDu ...
- reStructuredText学习
reStructuredText学习====================2015年4月1日 学习的最好方法就是尽快动手开始.不断迭代,不断完善. reStructuredText学习v0.1版本. ...
- CSS3 自动旋转
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...