C - Building a Space Station - poj 2031
空间站是有一些球状的房间组成的,现在有一些房间但是没有相互连接,你需要设计一些走廊使他们都相通,当然,有些房间可能会有重合(很神奇的样子,重合距离是0),你需要设计出来最短的走廊使所有的点都连接。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
using namespace std; #define maxn 105 struct point{double x, y, z, r;}p[maxn];
struct node
{
int u, v;
double len; friend bool operator < (node a, node b)
{
return a.len > b.len;
}
}; int f[maxn]; double Len(point a, point b)//求两点间的距离
{
double x = a.x - b.x;
double y = a.y - b.y;
double z = a.z - b.z;
double l = sqrt(x*x+y*y+z*z)-a.r-b.r; if(l < 0)l = 0; return l;
}
int Find(int x)
{
if(f[x] != x)
f[x] = Find(f[x]);
return f[x];
} int main()
{
int N; while(scanf("%d", &N) != EOF && N)
{
int i, j;
node s;
priority_queue<node>Q; for(i=1; i<=N; i++)
{
scanf("%lf%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z, &p[i].r);
f[i] = i;
} for(i=1; i<=N; i++)
for(j=i+1; j<=N; j++)
{
s.u = i, s.v = j;
s.len = Len(p[i], p[j]);
Q.push(s);
} double ans = 0; while(Q.size())
{
s = Q.top();Q.pop();
int u = Find(s.u), v = Find(s.v); if(u != v)
{
f[u] = v;
ans += s.len;
}
} printf("%.3f\n", ans);
} return 0;
}
C - Building a Space Station - poj 2031的更多相关文章
- Building a Space Station POJ - 2031
Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...
- (最小生成树) Building a Space Station -- POJ -- 2031
链接: http://poj.org/problem?id=2031 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6011 ...
- Building a Space Station POJ 2031 【最小生成树 prim】
http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...
- Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题
#include<iostream> #include<cmath> #include<algorithm> #include<cstdio> usin ...
- POJ 2031 Building a Space Station【经典最小生成树】
链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2031 Building a Space Station【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
- POJ 2031 Building a Space Station
3维空间中的最小生成树....好久没碰关于图的东西了..... Building a Space Station Time Limit: 1000MS Memory Li ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5173 Accepte ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...
随机推荐
- Linux学习笔记共享
从学习到现在,已经3个月了,还有不到一个月linux课程就要结束,大概的情况如下: 预科一周,主要是学习了网络,思科的内容 linux基础课程,从无到有 linux shell 脚本 linux项目实 ...
- HDU5301
题意:给n*m的矩形区域,剔除其中1*1的方块,然后用不同矩形块填充整个矩形区域,求需要的矩形块最大面积的最小值. 思路:先判把矩形矫正,然后特殊处理边值为奇数,且在中心点的情况,最后处理障碍在其他位 ...
- jquery的ajax方法:ajaxStart()和ajaxStop()
ajaxStart()方法: 当AJAX请求开始时,显示加载中的提示. $("#divMessage").ajaxStart(function(){ $(this).show(); ...
- 【转】Java学习之Iterator(迭代器)的一般用法 (转)
[转]Java学习之Iterator(迭代器)的一般用法 (转) 迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭 ...
- WPF 依赖属性与依赖对象
在介绍依赖属性之前,我先介绍下属性的历史 属性的历史: 早期C++的类中,只有字段及方法,暴露数据靠的是方法, 但是字段直接暴露会不安全,所以才用方法来暴露,在设置的时候加些约束,在MFC中 ...
- 访问快递100的rest的请求
转:http://blog.csdn.net/u011115507/article/details/9172679 查快递的时候发现了一个http://www.kaidi100.com 是金蝶旗下的下 ...
- 8.模板方法模式-[Head First 设计模式]
模板方法模式在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 要点: “模板方法”定义了算法的步骤,把这些步骤的实现延 ...
- Mysql 索引的基础(下)
如果需要存储大量的URL并需要根据URL进行搜索查找.如果使用B-Tree 来存储URL,存储的内容就会很大,因为URL本身都很长.正常情况下会有如下查询: SELECT id FROM url WH ...
- ActiveReports 交互式报表之向下钻取解决方案
在 ActiveReports 中可以动态的显示或者隐藏某区域的数据,通过该功能用户可以根据需要显示或者隐藏所关心的数据,结合数据排序.过滤等功能可以让用户更方便地分析报表数据. 本文中展示的是销售数 ...
- Python新手学习基础之数据结构-列表2 添加
insert 除了使用索引,我们还可以用列表的insert方法,在列表的指定位置添加新的值. insert的用法: list.insert(index, item) 例如: like_animals ...