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 ...
随机推荐
- codevs 1128 导弹拦截 (贪心)
/* 题目大体意思是两套系统好多导弹 怎样分配使得两个系统所拦截的最大半径之和最小 贪心:把距离1系统最远的 让2拦截 记好距离 然后按照距离1由远到近排序 对于每一个导弹 如果这之前的都给2拦截 则 ...
- matlab中的三维坐标系与旋转
1. matlab中的三维坐标系 matlab中的三维坐标系是使用的右手坐标系: 输入以下代码: >> plot3(0,0,0) >> xlabel('axis X') > ...
- node.js的ejs模版引擎
ejs版本是0.8.8,生成的views目录下面只有index.ejs and error.ejs,没有layout.ejs. D:\lianchuangfile\nodeDevelop\microb ...
- 关于开发C#中的asp.net中gridview控件的使用
原文网址:http://blog.sina.com.cn/s/blog_67f1b4b201017663.html 1.GridView无代码分页排序: 效果图: 1.AllowSorting设为Tr ...
- Html5 Canvas Text
html5 canvas中支持对text文本进行渲染;直接的理解就是把text绘制在画布上,并像图形一样处理它(可以加shadow.gradient.pattern.color fill等等):既然它 ...
- 程序里面的system.out.println()输出到其他位置,不输出到tomcat控制台。
设置startup.bat: call "%EXECUTABLE%" run %CMD_LINE_ARGS% >> ..\logs\kongzitai.txt 将sys ...
- jrae源码解析(一)
jare用java实现了论文<Semi-Supervised Recursive Autoencoders for Predicting Sentiment Distributions>中 ...
- [转] 详细整理:UITableView优化技巧
原文:http://www.cocoachina.com/ios/20150602/11968.html 最近在微博上看到一个很好的开源项目VVeboTableViewDemo,是关于如何优化 ...
- 使用mysql作为hive的元数据库
1.hive下载安装 2.下载mysql安装 3.以root用户进入mysql命令行:mysql -uroot -p(提示输入密码) 4.创建hive的元数据库:create databa ...
- 织梦dedecms网站六大SEO优化技巧(转帖)
一个排名好的网站离不开好的cms,当然不同cms各有各的好处,因此我们在上线新网站的时候,要针对不同的情况因地制宜,选择不同的网站管理系统来做seo优化,现在使用比较流行的cms是织梦dedecms, ...