题目:

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. pd.read_csv() 、to_csv() 之 常用参数

    本文简单介绍一下read_csv()和 to_csv()的参数,最常用的拿出来讲,较少用的请转到官方文档看. 一.pd.read_csv() 作用:将csv文件读入并转化为数据框形式. pd.read ...

  2. 学习笔记《Mustache》模板

    Mustache 是一款经典的前端模板引擎,在前后端分离的技术架构下面,前端模板引擎是一种可以被考虑的技术选型,随着重型框架(AngularJS.ReactJS.Vue)的流行,前端的模板技术已经成为 ...

  3. Ansible第一章:基础认识--小白博客

    ansible Ansible:Ansible的核心程序Host Lnventory:记录了每一个由Ansible管理的主机信息,信息包括ssh端口,root帐号密码,ip地址等等.可以通过file来 ...

  4. 控制结构(2): 卫语句(guard clause)

    // 上一篇:分枝/叶子(branch/leaf) // 下一篇:状态机(state machine) 基于语言提供的基本控制结构,更好地组织和表达程序,需要良好的控制结构. 典型代码: 同步版本 f ...

  5. 解决虚拟机下安装CentOS无法上网

    Centos7默认是不启用有线网卡的,需要手动开启. 操作步骤如下: 首先,打开终端.cd /etc/sysconfig/network-scripts/ls 查看一下ifcfg-eno后面对应的数字 ...

  6. java异常处理规范

    异常处理的优势[存在意义]:异常检测者有检测出异常的能力,但不知道在出现该异常的情况下应该怎么处理.故库方法一般会抛出异常给调用者来处理.所以总结而言,异常处理的优势就是,将处理错误(调用者处理)从检 ...

  7. OOM分析工具

    OOM (OutOfMemoryError) 1.MAT工具 在eclipse中安装.Help>Eclipse Marketplace 搜索MAT 接下来运行程序,run configratio ...

  8. J2SE学习笔记

    如何学习Java 一.面向对象设计思想 1.面向对象:开车去新疆,车怎么去的我不管,我只调用车的go() 方法即可. 2.类和对象:类可以看成一类对象的模板,对象可以看成该类的一个具体实例. 3.类和 ...

  9. Pyspark-SQL 官方 API 的一些梳理(上)

    在 Pyspark 操纵 spark-SQL 的世界里借助 session 这个客户端来对内容进行操作和计算.里面涉及到非常多常见常用的方法,本篇文章回来梳理一下这些方法和操作. class pysp ...

  10. AngularJS 1.x系列:AngularJS控制器(3)

    1. 控制器(Controller)定义 控制器(Controller)在AngularJS中作用是增强视图(View),AngularJS控制器是一个构造方法,用来向视图(View)中添加额外功能. ...