G - Arctic Network - poj2349
在北极圈有一些基地,这些基地需要建立通讯网络,他们可以通过卫星直接通信或者无线通信,基地有S个卫星,N个基地,不过无线通信的传输距离是D,距离越远费用越高,现在想知道D最小是多少。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
using namespace std; #define maxn 505 int f[maxn];
struct node
{
int u, v;
double len;
friend bool operator < (node a, node b)
{
return a.len > b.len;
}
};
struct point{double x, y;}p[maxn];
double Len(point a, point b)
{
double x = a.x - b.x;
double y = a.y - b.y;
double l = sqrt(x*x+y*y); return l;
}
int Find(int x)
{
if(f[x] != x)
f[x] = Find(f[x]);
return f[x];
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int S, N, u, v;
node s;
priority_queue<node> Q; scanf("%d%d", &S, &N); for(s.u=1; s.u<=N; s.u++)
{
f[s.u] = s.u;
scanf("%lf%lf", &p[s.u].x, &p[s.u].y);
for(s.v=1; s.v<s.u; s.v++)
{
s.len = Len(p[s.u], p[s.v]);
Q.push(s);
}
} while(Q.size() && S < N)
{
s = Q.top();Q.pop();
u = Find(s.u), v = Find(s.v); if(u != v)
{
S++;
f[u] = v;
}
} printf("%.2f\n", s.len);
} return 0;
}
G - Arctic Network - poj2349的更多相关文章
- G - Arctic Network
G - Arctic Network #include<cmath> #include<cstdio> #include<cstring> #include&l ...
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19113 Accepted: 6023 D ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- POJ2349 Arctic Network(Prim)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16968 Accepted: 5412 D ...
- 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 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 ...
随机推荐
- 把C#对象转换为json字符串
下面的代码写在ashx一般处理程序中 声明context.Response.ContentType = "application/json";代表服务器端返回的数据为json字符串 ...
- .NET六大剑客:栈、堆、值类型、引用类型、装箱和拆箱
.NET六大剑客:栈.堆.值类型.引用类型.装箱和拆箱 一.“堆”,“栈”专区 这两个字我相信大家太熟悉了,甚至于米饭是什么?不知道...“堆”,“栈”是什么?哦,这个知道... 之前我也写过一篇堆栈 ...
- css.day02.eg
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 重新开始学习javase_一切都是对象
@学习thinking in java 一,一切都是对象 用句柄操纵对象 每种编程语言都有自己的数据处理方式.比如说c与c++中的指针,而java中尽管将一切都“看作”对象,但操纵的标识符实际是指向一 ...
- 【USACO 1.2.1】挤牛奶
[问题描述] 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300时刻(从5点开始计时,秒为单位)给他的牛挤奶,一直到1000时刻.第二个农民在700时刻开始,在 1200时刻结束.第 ...
- (转载)小课堂UI-有关配色的一个小技巧
- Javascript模块化编程:模块的写法
声明:本文转载自:阮一峰的网络日志,原文地址http://www.ruanyifeng.com/blog/2012/10/javascript_module.html,http://www.ruany ...
- ASP.NET程序从IIS6移植到IIS7时出现500.22错误
最可能的原因: • 此应用程序在 system.web/httpModules 节中定义配置. 可尝试的操作: • 将配置迁移到 system.webServer/modules 节 ...
- jquery 当前页导航高亮显示
<script type="text/javascript"> $(document).ready(function(){ var myNav = $("#n ...
- 简化的nginx多进程模型demo
//version 1:以下代码仅演示nginx多进程模型[test@vm c]$ cat mynginx.c#include <stdio.h> #include <string. ...