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 ...
随机推荐
- 176. [USACO Feb07] 奶牛聚会
#include<iostream> #include<cstdio> #include<cstring> #include<queue> #defin ...
- C# Wpf异步修改UI,多线程修改UI(二)
1.使用定时器异步修改 这是相对比较简单的方法 在Wpf中定时器使用DiapatcherTimer,不使用Timer原因: 在一个应用程序中,Timer会重复生成time事件,而DispatcherT ...
- dedecms 使noflag参数及其过滤多个属性的修改方法
noflag='h' 是代表不包含头条属性的意思,其中flag就是属性, 自定义属性值:头条[h]推荐[c]图片[p]幻灯[f]滚动[s]跳转[j]图文[a]加粗[b]. noflag过滤多个属性的修 ...
- 用Global.asax实现伪静态.
在Global.asax文件里添加Application_BeginRequest事件处理.添加如下代码: 1 protected void Application_BeginRequest(Obje ...
- ubuntu远程连接
apt-cache search openssh-server //直接用apt-get install openssh-server安装.记不清包名字时可用apt-cache search o ...
- Object Storage(Swift)安装过程——Havana
自从看了Havana安装文档有关Swift的安装一节,发现H版的安装过程与以前还是有些差别的.不过大致过程还是那些.下面简单介绍下我们安装的过程吧,具体请参考官方文档http://docs.opens ...
- jquery mobile 栅格化
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- extjs中datefield组件的使用
xtype: 'datefield', id: 'dateShangmfa', name: 'dateShangmfa', fieldLabel: '日期',//设置标签文本 editable: fa ...
- HDU 4627(最小公倍数最大问题)
HDU 4627 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- Azure IoT
微软Azure IoT 国外物联网平台初探(二)——微软Azure IoT 马智 平台定位 连接设备.其它 M2M 资产和人员,以便在业务和操作中更好地利用数据. 连接 IoT 设备 将所有设备连 ...