题目:

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. SpringBoot开发案例之整合Activiti工作流引擎

    前言 JBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baeyens离开JBoss后,JBPM的下一个版本jBPM5完全放弃了jBPM4的基础代码,基于Drools Flow重头来过,目前官 ...

  2. SpringCloud(4)熔断器 Hystrix

    在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用.为了保证其高可用,单个服务 ...

  3. 在 .NET Core 中结合 HttpClientFactory 使用 Polly(上篇)

    译者:王亮作者:Polly 团队原文:http://t.cn/EhZ90oq 译者序一:前两天写了一篇文章 .NET Core 开源项目 Polly 介绍,在写这篇文章查看 Polly 资料时,看到了 ...

  4. 如何在.net 4.0下安装TLS1.2的支持

    原始出处:www.cnblogs.com/Charltsing/p/Net4TLS12.html 作者QQ: 564955427 最近提交请求发生错误:不支持请求的协议,研究了一下TLS1.2,发现这 ...

  5. Ocr答题辅助神器 OcrAnswerer4.x,通过百度OCR识别手机文字,支持屏幕窗口截图和ADB安卓截图,支持四十个直播App,可保存题库

    http://www.cnblogs.com/Charltsing/p/OcrAnswerer.html 联系qq:564955427 最新版为v4.1版,开放一定概率的八窗口体验功能,请截图体验(多 ...

  6. axios拦截器

    import axios from "axios"; axios.interceptors.response.use(response => { //=>设置响应拦截器 ...

  7. NOIP2001提高组复赛B 数的划分

    题目链接:https://ac.nowcoder.com/acm/contest/249/B 题目大意: 略 分析1(记忆化搜索): 方法为减而治之,把n划分成k份的答案就相当于每次把n分成a,b两个 ...

  8. mysql client--笔记-修改密码-登录-查看数据库-创建数据库

    1 登录 mysql client 打开 mysql client -输入密码 123 回车 2 show database; ---显示数据库 3 切换数据库:use mysql 4 describ ...

  9. python 基础篇练习题

    一.练习题 # 1.统计元组中所有数据属于字符串的个数,提示:isinstance() # 数据:t1 = (1, 2, '3', '4', 5, '6') # 结果:3 # 2.将以下数据存储为字典 ...

  10. poj2778(AC自动机+矩阵快速幂)

    题意:给你n个字符串,问你长度为m的字符串且字符串中不含有那n个子串的字符串的数量 解题思路:这道题一开始就不太懂,还以为是组合数学的题目,后面看了别人的博客,才知道这是属于AC自动机的另一种用法,是 ...