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 ...
随机推荐
- SPOJ 345 - Mixtures 区间动态规划
有n个混合物排成一排,每个混合物有一个颜色值0<=color<=99, 规定合并只能合并相邻两个, 将颜色a的混合物与颜色b的混合物合并后,颜色为( a+b ) % 100,并产生a*b的 ...
- MsSql省市联动表
drop table area CREATE TABLE [dbo].[Area] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NOT NULL , ) ...
- python字符串replace()方法
python字符串replace()方法 >>> help(str.replace)Help on method_descriptor:replace(...) S.repla ...
- Android开发--WIFI实现
wifi的基本结构 在Android的官方文档中定义了如下五种状态: WIFI_STATE_DISABLING WIFI网卡正在关闭 0 WIFI_STATE_DISABLED WIFI网卡不 ...
- JavaScript调用后台的三种方法实例(包含两种Ajax)
方法一:直接使用<%=%>调用(ASPX页面) 前台JS,代码如下: <script type="text/javascript"> var methodS ...
- codevs4203山区建小学
/* 状态:f[i][j] 前i个村庄已经建了j个学校 转移:f[i][j]=min(f[i][j],f[ii][j-1]+s[ii+1][i]) 1<=ii<=i-1 */ #inclu ...
- document.all用法
document.all用法 一. document.all是页面内所有元素的一个集合.例如: document.all(0)表示页面内第一个元素二.document.all可以判断浏览器 ...
- Modernizr——为HTML5和CSS3而生!
原文地址:http://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/ 堂主译文地址:ht ...
- photoshop mac版下载及破解
1.下载 直接百度photoshop,就可以找到百度的下载源: 2.破解 http://zhidao.baidu.com/question/581955095.html
- 【转】UITextView的使用详解
//初始化并定义大小 UITextView *textview = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, 280, 30)]; te ...