poj 2031 Building a Space Station(最小生成树,三维,基础)
只是坐标变成三维得了,而且要减去两边的半径而已
//最小生成树,只是变成三维的了
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; #define inf 999999999
#define M 110
double mat[M][M];
struct tt
{
double x,y,z,r;
}d[M]; double prim(int n,int sta)
{
int mark[M],i,j;
double dis[M],sum=;
for(i=;i<n;i++)
{
dis[i]=mat[sta][i];
mark[i]=;
}
mark[sta]=;
for(i=;i<n;i++)
{
double minn=inf*1.0;
int flag=-;
for(j=;j<n;j++)
{
if(mark[j]==&&dis[j]<minn)
{
minn=dis[j];
flag=j;
}
}
if(flag!=-)
{
mark[flag]=;
sum=sum+dis[flag];
for(j=;j<n;j++)
{
if(dis[j]>mat[flag][j])
dis[j]=mat[flag][j];
}
}
}
return sum;
} int main()
{
int i,j,n;
double aa;
while(scanf("%d",&n),n)
{
for(i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&d[i].x,&d[i].y,&d[i].z,&d[i].r);
for(j=;j<i;j++)
{
aa=sqrt((d[i].x-d[j].x)*(d[i].x-d[j].x)+(d[i].y-d[j].y)*(d[i].y-d[j].y)+(d[i].z-d[j].z)*(d[i].z-d[j].z))-d[i].r-d[j].r;
aa=aa>? aa:;
mat[i][j]=mat[j][i]=aa;
}
}
printf("%.3lf\n",prim(n,));
}
return ;
}
poj 2031 Building a Space Station(最小生成树,三维,基础)的更多相关文章
- 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 最小生成树模板
题目大意:在三维坐标中给出n个细胞的x,y,z坐标和半径r.如果两个点相交或相切则不用修路,否则修一条路连接两个细胞的表面,求最小生成树. 题目思路:最小生成树树模板过了,没啥说的 #include& ...
- 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 (最小生成树)
Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...
- 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 三维球点生成树Kruskal
Building a Space Station You are a member of the space station engineering team, and are assigned a ...
- POJ 2031 Building a Space Station【最小生成树+简单计算几何】
You are a member of the space station engineering team, and are assigned a task in the construction ...
- POJ 2031 Building a Space Station (计算几何+最小生成树)
题目: Description You are a member of the space station engineering team, and are assigned a task in t ...
- POJ - 2031C - Building a Space Station最小生成树
You are a member of the space station engineering team, and are assigned a task in the construction ...
随机推荐
- 单元测试+修改BUG
程序源代码: #include<iostream> using namespace std; int Largest(int list[], int length) { int i, ma ...
- AOJ 0121 Seven Puzzle
7 パズル 7 パズルは 8 つの正方形のカードとこれらのカードがぴたりと収まる枠で構成されています.それぞれのカードには.互いに区別できるように 0, 1, 2, ..., 7 と番号がつけられてい ...
- module graceful-fs for npm
问题: 今天使用hexo时发现错误,hexo:command not found.于是重新安装hexo.但是在安装好npm后,却发现运行 npm 出现错误,没有找到模块graceful-fs,在纠结了 ...
- jQuery EasyUI 数据网格 - 启用行内编辑(转自http://www.runoob.com/jeasyui/jeasyui-datagrid-datagrid12.html)
可编辑的功能是最近添加到数据网格(datagrid)的.它可以使用户添加一个新行到数据网格(datagrid).用户也可以更新一个或多个行.本教程向您展示如何创建一个数据网格(datagrid)和内联 ...
- 惠普M1005打印机无法自动进纸的问题
惠普M1005打印机无法自动进纸的问题 问题起因 其实我也不太清楚是什么起因,前一天用的好好的惠普M1005打印机,在打印时没有直接打印,会弹出一个提示对话框,同时打印机显示屏上显示“load tra ...
- [大牛翻译系列]Hadoop(15)MapReduce 性能调优:优化MapReduce的用户JAVA代码
6.4.5 优化MapReduce用户JAVA代码 MapReduce执行代码的方式和普通JAVA应用不同.这是由于MapReduce框架为了能够高效地处理海量数据,需要成百万次调用map和reduc ...
- Struts 2简单配置分析
要配置Struts 2,首先先要有Struts 2的Jar包,可以去Struts的官网下载(http://struts.apache.org/),这里有3个GA版本可以选择下载,我选择的是最新的2.2 ...
- 从零开始学ios开发(十八):Storyboards(下)
这篇我们完成Storyboards的最后一个例子,之前的例子中没有view之间的切换,这篇加上这个功能,使Storyboards的功能完整呈现.在Storyboards中负责view切换的东西叫做“s ...
- iTween基础之Move(移动)
1,五种移动方法:2, 函数的基础属性及用法 原文地址:http://blog.csdn.net/dingkun520wy/article/details/50476864 iTween官网:http ...
- Codeforces Round #333 DIV2
D: B. Lipshitz Sequence time limit per test 1 second memory limit per test 256 megabytes input stand ...