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 ...
随机推荐
- C++ 11 之初始化
1.4中不同初始化的形式 a.string s("zhl").int i(3); //括号初始化 b.string s="zhl".int ...
- 用CSS实现Firefox 和IE 都支持的Alpha透明效果
有的时候,为了实现一些特殊效果,需要将页面元素变透明,本文介绍的就是用 CSS 实现 Firefox 和 IE 都支持的 Alpha 透明效果.CSS: filter:alpha(opacity=50 ...
- 我的总结SVN的使用
SVN平时在用时,一般要做到早上一次更新,中间每做出一个模块就要提交,就是一次更新,多次提交, SVN在修改公共类,配置文件时一定要注意,如果修改的是配置文件中的东西,这样修改完之后一定要提交, 如果 ...
- jquery hover事件冒泡解决方法
$(this).hover(function(event){ $(this).addClass("cur"); event.stopPropagation(); ...
- linux下配置Apache基于加密的认证访问
1.首先要确认安装了 mod_ssl模块 我的机器是centos是系统,执行下面命令 yum install -y mod_ssl 2.用openssl工具生成密钥,证书请求文件,证书 在/usr/l ...
- c++ 进程权限的提升
//提升权限 void CManageProcessDlg::DebugPrivilege() { HANDLE hToken = NULL; //打开当前进程的访问令牌 int hRet = ...
- Eclipse导入android包错误
错误提示:Invalid project description… 解决方案:假设你的工作空间是workshop,那么你可以在你的workshop下新建一个文件夹,然后放入你的包,再在Eclipse中 ...
- for xml path以及sql合并查询
sql中for xml path的用法. http://www.cnblogs.com/yanghaibo/archive/2010/06/04/1751405.html
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 【Go】为什么用go; Golang Erlang 前世今生
给自己一条退路,再次比较Erlang和Golang 2014-6-28 陈叶皓 chenyehao@gmail.com 雨天的周末,适合码字的时节... 一年前我开始学习go语言的时候,如获至宝,既有 ...