#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 200
double co(double a,double b) {
return  (a-b)*(a-b);
}
struct node {
double x,y,z,r;
}a[N];
struct nodee{
double len;
int x,y;
}map[N*N];
int pre[N];
int find(int x) {
if(x!=pre[x])
pre[x]=find(pre[x]);
return pre[x];
}
int cmp(const void *b,const void *c) {
return (*(struct nodee *)b).len>(*(struct nodee *)c).len?1:-1;
}
int main() {
double r,sum;
int n,i,j,k,e,w;
while(scanf("%d",&n),n) {
for(i=1;i<=n;i++)
pre[i]=i;
for(i=1;i<=n;i++) 
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z,&a[i].r);
k=0;
for(i=1;i<n;i++) 
for(j=i+1;j<=n;j++) {
r=sqrt(co(a[i].x,a[j].x)+co(a[i].y,a[j].y)+co(a[i].z,a[j].z));
map[k].x=i;
map[k].y=j;
if(r<=a[i].r+a[j].r) 
map[k].len=0;
else
map[k].len=r-(a[i].r+a[j].r);
k++;
}
qsort(map,k,sizeof(map[0]),cmp);
j=1;sum=0;
for(i=0;i<k&&j<n;i++) {
e=find(map[i].x);
w=find(map[i].y);
if(e!=w) {
pre[e]=w;
j++;
sum+=map[i].len;
}
}
printf("%.3f\n",sum);
}
return 0;
}

poj 2031的更多相关文章

  1. POJ 2031 prim

    Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4400 Accepted: 2 ...

  2. Building a Space Station POJ - 2031

    Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...

  3. poj 2031 Building a Space Station(prime )

    这个题要交c++, 因为prime的返回值错了,改了一会 题目:http://poj.org/problem?id=2031 题意:就是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能 ...

  4. POJ - 2031 Building a Space Station(计算几何+最小生成树)

    http://poj.org/problem?id=2031 题意 给出三维坐标系下的n个球体,求把它们联通的最小代价. 分析 最小生成树加上一点计算几何.建图,若两球体原本有接触,则边权为0:否则边 ...

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

    链接: http://poj.org/problem?id=2031 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6011 ...

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

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

  7. POJ - 2031 Building a Space Station 【PRIME】

    题目链接 http://poj.org/problem?id=2031 题意 给出N个球形的 个体 如果 两个个体 相互接触 或者 包含 那么 这两个个体之间就能够互相通达 现在给出若干个这样的个体 ...

  8. Building a Space Station POJ 2031 【最小生成树 prim】

    http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...

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

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

  10. zoj 1718 poj 2031 Building a Space Station

    最小生成树,用了Kruskal算法.POJ上C++能过,G++不能过... 算出每两个圆心之间的距离,如果距离小于两半径之和,那么这两个圆心之间的距离直接等于0,否则等于距离-R[i]-R[j]. # ...

随机推荐

  1. [python基础] csv.wirterow()报错UnicodeEncodeError

    python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错,python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一 ...

  2. bzoj2427 [HAOI2010]软件安装——缩点+树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2427 今天的考试题...好不容易一次写对了树形DP,却没发现有环的情况... 发现自己 ta ...

  3. bzoj4591 [Shoi2015]超能粒子炮·改——组合数学(+求阶乘逆元新姿势)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4591 这题不是很裸啊(所以我就不会了) 得稍微推导一下,看这个博客好了:https://bl ...

  4. 4.28 QBXT模拟赛

    NOIP2016提高组模拟赛 ——By wangyurzee7 中文题目名称 迷妹 膜拜 换数游戏 英文题目与子目录名 fans mod game 可执行文件名 fans mod game 输入文件名 ...

  5. [Swift通天遁地]七、数据与安全-(4)CoreData数据的增、删、改、查

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. day02_12/12/2016_bean的实例化之构造器方式

  7. Unity通过指定摄像机截屏

    简介 介于照抄网上之前的截图教程,然后在实际应用过程中出现了一些小小的问题,修正了一下下,特此分享一下 PS:代码在后面 原理 原理很简单,就是将一个相机的内容渲染到一个贴图上,然后将贴图保存为图片 ...

  8. HTML 表格与表单 个人简历

    <title>个人简历</title></head> <body background="1e30e924b899a9015b946ac41f950 ...

  9. Echarts 出现不明竖线解决方案

    Echarts出现了不明竖线,百思不得其解.去查相应的解决方案也没有找到. 后来自己点来点去,突然感觉像是上一个Echarts遗留的. 然后去Echarts官网看到了 clear()方法,这个方法可以 ...

  10. win32动态库

    先讲一个基本的动态库,功能为自定义一个动态库,里面有一个函数MyMessage实现弹出MessageBox. 1. 先在头文件中定义: #ifdef __cplusplus #define EXPOR ...