题目:

Description

You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. 
The space station is made up with a number of units, called cells. All cells are sphere-shaped, but their sizes are not necessarily uniform. Each cell is fixed at its predetermined position shortly after the station is successfully put into its orbit. It is quite strange that two cells may be touching each other, or even may be overlapping. In an extreme case, a cell may be totally enclosing another one. I do not know how such arrangements are possible. 
All the cells must be connected, since crew members should be able to walk from any cell to any other cell. They can walk from a cell A to another cell B, if, (1) A and B are touching each other or overlapping, (2) A and B are connected by a `corridor', or (3) there is a cell C such that walking from A to C, and also from B to C are both possible. Note that the condition (3) should be interpreted transitively. 
You are expected to design a configuration, namely, which pairs of cells are to be connected with corridors. There is some freedom in the corridor configuration. For example, if there are three cells A, B and C, not touching nor overlapping each other, at least three plans are possible in order to connect all three cells. The first is to build corridors A-B and A-C, the second B-C and B-A, the third C-A and C-B. The cost of building a corridor is proportional to its length. Therefore, you should choose a plan with the shortest total length of the corridors. 
You can ignore the width of a corridor. A corridor is built between points on two cells' surfaces. It can be made arbitrarily long, but of course the shortest one is chosen. Even if two corridors A-B and C-D intersect in space, they are not considered to form a connection path between (for example) A and C. In other words, you may consider that two corridors never intersect. 
 

Input

The input consists of multiple data sets. Each data set is given in the following format. 

x1 y1 z1 r1 
x2 y2 z2 r2 
... 
xn yn zn rn 
The first line of a data set contains an integer n, which is the number of cells. n is positive, and does not exceed 100. 
The following n lines are descriptions of cells. Four values in a line are x-, y- and z-coordinates of the center, and radius (called r in the rest of the problem) of the sphere, in this order. Each value is given by a decimal fraction, with 3 digits after the decimal point. Values are separated by a space character. 
Each of x, y, z and r is positive and is less than 100.0. 
The end of the input is indicated by a line containing a zero. 
 

Output

For each data set, the shortest total length of the corridors should be printed, each in a separate line. The printed values should have 3 digits after the decimal point. They may not have an error greater than 0.001. 
Note that if no corridors are necessary, that is, if all the cells are connected without corridors, the shortest total length of the corridors is 0.000. 
 

Sample Input

3
10.000 10.000 50.000 10.000
40.000 10.000 50.000 10.000
40.000 40.000 50.000 10.000
2
30.000 30.000 30.000 20.000
40.000 40.000 40.000 20.000
5
5.729 15.143 3.996 25.837
6.013 14.372 4.818 10.671
80.115 63.292 84.477 15.120
64.095 80.924 70.029 14.881
39.472 85.116 71.369 5.553
0

Sample Output

20.000
0.000
73.834

题意:
给出n个圆 如果两圆相交 则两圆间距离为0 求最小生成树 思路:
先用计算几何内容求出任意两圆间距离 然后连边 如果两圆相交 mp[i][j]=0 如果两圆不相交 mp[i][j]=两圆距离-两圆半径和
处理成矩阵图 用prim算法跑最小生成树

代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
const double eps=1e-;
int n;
int vis[maxn];
double mp[maxn][maxn],dis[maxn]; int dps(double x){
if(fabs(x)<eps) return ;
return x>?:-;
} struct Point{
double x,y,z,r;
}kk[maxn]; double len(Point a,Point b){
return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)+(b.z-a.z)*(b.z-a.z));
} int main(){
while(~scanf("%d",&n)){
if(n==) break;
memset(mp,,sizeof(mp));
memset(dis,,sizeof(dis));
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&kk[i].x,&kk[i].y,&kk[i].z,&kk[i].r);
}
for(int i=;i<=n;i++){
dis[i]=(double)inf;
for(int j=i+;j<=n;j++){
double tmp=len(kk[i],kk[j]);
double tmp2=kk[i].r+kk[j].r;
if(dps(tmp-tmp2)<=) mp[i][j]=mp[j][i]=0.0;
else mp[i][j]=mp[j][i]=tmp-tmp2;
}
}
for(int i=;i<=n;i++){
dis[i]=mp[][i];
}
dis[]=0.0;
vis[]=;
double sum=;
int tmp;
for(int i=;i<=n;i++){
tmp=inf;
double minn=(double)inf;
for(int j=;j<=n;j++){
if(vis[j]== && dis[j]<minn){
tmp=j;
minn=dis[j];
}
}
if(tmp==inf) break;
vis[tmp]=;
sum+=minn;
for(int j=;j<=n;j++){
if(vis[j]== && dis[j]>mp[tmp][j])
dis[j]=mp[tmp][j];
}
}
printf("%.3f\n",sum);
} return ;
}

POJ 2031 Building a Space Station (计算几何+最小生成树)的更多相关文章

  1. POJ 2031 Building a Space Station (最小生成树)

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

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

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

  3. POJ 2031 Building a Space Station【最小生成树+简单计算几何】

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

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

    只是坐标变成三维得了,而且要减去两边的半径而已 题目 //最小生成树,只是变成三维的了 #define _CRT_SECURE_NO_WARNINGS #include<stdlib.h> ...

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

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

  6. POJ 2031 Building a Space Station (最小生成树)

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

  7. POJ 2031 Building a Space Station

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

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

  9. POJ 2031 Building a Space Station (prim裸题)

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

随机推荐

  1. TPYBoard开发板搭建,实现隐秘通信

    一.准备工作 lTPYBoard v102(简称v102) 1块 lTPYBoard v202(简称v202) 1块 l杜邦线.MicroUSB数据线 若干 (成本100元以内,某宝上可以买到) 附上 ...

  2. C语言的3种参数传递方式

    参数传递,是在程序运行过程中,实际参数就会将参数值传递给相应的形式参数,然后在函数中实现对数据处理和返回的过程,方法有3种方式 值传递 地址传递 引用传递 tips: 被调用函数的形参只有函数被调用时 ...

  3. Windows 10 安装过程中,在自定义登录页面进入审核模式

    按ctrl-f3进入审核模式 https://msdn.microsoft.com/zh-cn/windows/hardware/commercialize/manufacture/desktop/b ...

  4. 在OSGI容器Equinox中嵌入HttpServer

    原文地址:https://liugang594.iteye.com/blog/1328050 简单介绍一下如何在一个osgi的bundle中内嵌使用http服务 一.基础 首先看看在OSGI中怎么启动 ...

  5. redis--小白博客

    概述 redis是一种nosql数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,并且他比memcached支持更多的数据结构(string,list列表 ...

  6. Centos查看tomcat状态及操作

    启动:一般是执行sh tomcat/bin/startup.sh 查看:执行ps -ef |grep tomcat 输出如下 www 5144 ...等等.Bootstrap start 说明tomc ...

  7. 基本环境安装: Centos7+Java+Hadoop+Spark+HBase+ES+Azkaban

    1.  安装VM14的方法在 人工智能标签中的<跨平台踩的大坑有提到> 2. CentOS分区设置: /boot:1024M,标准分区格式创建. swap:4096M,标准分区格式创建. ...

  8. HDU 3518 Boring counting

    题目:Boring counting 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3518 题意:给一个字符串,问有多少子串出现过两次以上,重叠不能算两次 ...

  9. DAO 四个包的建立

    一.DAO 四个包的建立,降低代码之间的耦合性? 之前写代码,都是在一个包下.代码耦合性较高,不利于后期的维护. dao(代码分层?) 有利于后期的维护代码,修改方便. com.aaa.dao 存放d ...

  10. Python——使用Pycharm连接数据库