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 题 ...
随机推荐
- linux小白成长之路11————linux命令大全
1. 启动,关机,登入,登出相关命令 登录:login 登出:logout 登出:exit 停止系统:shutdown 停止系统:halt 重启动:reboot 切断电源:poweroff 把内存里的 ...
- C#过时方法标记
1.当遇到过时或废弃的方式 函数怎么办 [Obsolete]特性解决你的困惑 1.1:当方法已经完成相关兼容 可以保留时
- 白话容器namespace
进入正题之前是例行装X环节: 过年7天吃的,花了45天又回来了. 近年来容器大火,也正是因为容器,生生灭掉了一个IT岗位!哥也是被生生的逼上了邪路. 那究竟什么是容器呢? 就三个字:它就是个进程!(多 ...
- CCF|跳一跳
import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner scan ...
- windows server 2008 r2 IIS7下网站配置 只允许指定的IP地址访问
步骤一.找到ip地址和域限制 步骤二.添加全部拒绝 步骤三.添加允许访问的ip地址(局域网填写局域网ip,公网填写公网ip) 步骤四:如果想要拒绝某些ip访问,直接在规则中添加拒绝条目就可以
- swift class type isa-swizzling
class 是引用类型,生成的实例分布在 Heap(堆) 内存区域上,在 Stack(栈)只存放着一个指向堆中实例的指针.因为考虑到引用类型的动态性和 ARC 的原因,class 类型实例需要有一块单 ...
- laravel 只有/login路由403,如何解决
链接/login自动转跳到/login/导致找不到 /public/login/ 目录导致403; 将路由中\login改为\login1访问正常,但login依然403,而不是未找到路由 链接/lo ...
- C# 处理年月日提取时间
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Oracle数据库自定义函数练习20181031
--测试函数3 CREATE OR REPLACE FUNCTION FN_TEST3 (NUM IN VARCHAR2) RETURN VARCHAR2 IS TYPE VARCHAR2_ARR ) ...
- bash基础——管道符、通配符
1.多命令顺序执行 多命令顺序执行 格式 作用 ; 命令1 ; 命令2 多个命令之间没有任何逻辑联系 && 命令1&&命令2 逻辑与 当命令1正确执行,则命令2才会执行 ...