poj 2031 Building a Space Station(最小生成树,三维,基础)

时间:2022-08-31 15:41:45

只是坐标变成三维得了,而且要减去两边的半径而已

题目

//最小生成树,只是变成三维的了
#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(最小生成树,三维,基础)的更多相关文章

  1. POJ 2031 Building a Space Station &lpar;最小生成树&rpar;

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5173   Accepte ...

  2. POJ 2031 Building a Space Station 最小生成树模板

    题目大意:在三维坐标中给出n个细胞的x,y,z坐标和半径r.如果两个点相交或相切则不用修路,否则修一条路连接两个细胞的表面,求最小生成树. 题目思路:最小生成树树模板过了,没啥说的 #include& ...

  3. POJ 2031 Building a Space Station【经典最小生成树】

    链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  4. POJ 2031&Tab; Building a Space Station (最小生成树)

    Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...

  5. poj 2031 Building a Space Station【最小生成树prime】【模板题】

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5699   Accepte ...

  6. POJ 2031 Building a Space Station

    3维空间中的最小生成树....好久没碰关于图的东西了.....              Building a Space Station Time Limit: 1000MS   Memory Li ...

  7. 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 ...

  8. POJ 2031 Building a Space Station【最小生成树&plus;简单计算几何】

    You are a member of the space station engineering team, and are assigned a task in the construction ...

  9. POJ 2031 Building a Space Station &lpar;计算几何&plus;最小生成树&rpar;

    题目: Description You are a member of the space station engineering team, and are assigned a task in t ...

  10. POJ - 2031C - Building a Space Station最小生成树

    You are a member of the space station engineering team, and are assigned a task in the construction ...

随机推荐

  1. HashSet HashTable 与 TreeSet

    HashSet<T>类 HashSet<T>类主要是设计用来做高性能集运算的,例如对两个集合求交集.并集.差集等.集合中包含一组不重复出现且无特性顺序的元素. HashSet& ...

  2. 如何查看Linux的系统是64位的还是32位的

    可以用命令“getconf LONG_BIT”查看,如果返回的结果是32则说明是32位,返回的结果是64则说明是64位. 此外还可以使用命令“uname -a”查看,输出的结果中,如果有x86_64就 ...

  3. hdu1506 dp

    //Accepted 1428 KB 62 ms // #include <cstdio> #include <cstring> #include <iostream&g ...

  4. js中substr&comma;substring&comma;indexOf&comma;lastIndexOf等的用法

    1.substrsubstr(start,length)表示从start位置开始,截取length长度的字符串. var src="images/off_1.png";alert( ...

  5. VB&period;NET生成重复窗体

    Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...

  6. ionic3 添加多个自定义组件

    往往我们创建自定义组件一般都不止只会创建一个自定义组件,创建多个方式如下. 1.创建自定义组件 ionic g component select-car-no ionic g component ae ...

  7. zigbee组网函数的一些用法

    1.NLME_PermitJoiningRequest(0)  :(1)值0x00:表示禁止加入网络  (2)值0x01-0xFE:表示允许链接的秒数 (3) 值0xff:表示启用网络 同时此函数:是 ...

  8. Excel 导出通用类

    public class ExportToExcelHelper { public static void ExportExcel(DataTable dt) { try { //创建一个工作簿 IW ...

  9. hdu2509 Be the Winner 博弈

    Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged ...

  10. 2&rpar; 下载Maven

    http://maven.apache.org/ http://maven.apache.org/download.cgi Maven 3.3.3 (Binary tar.gz) Maven 3.3. ...