#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. ubuntu系统快捷键设置

    1.打开'系统设置' 2.点击键盘 3.选择快捷键,查看和修改对应的快捷键.

  2. Flink之Stateful Operators

    Implementing Stateful Functions source function的stateful看官网,要加lock Declaring Keyed State at the Runt ...

  3. 【转】pycharm常用快捷键

    转自:http://www.2cto.com/os/201410/341542.html 转来珍藏着,以后慢慢完善. 编辑类: Ctrl + Space 基本的代码完成(类.方法.属性)Ctrl + ...

  4. PCB SQL SERVER 发送邮件(异步改同步)

    采用SQL SERVER发送邮件是队列方式(异步)发送邮件,所以在我们执行发送邮件后,无法立即获取到邮件是否发送成功了,而在PCB行业实际应用中是需要立即获取发送邮件是否成功的状态来决定下一步逻辑该如 ...

  5. codeforces——模拟

    805 B. 3-palindrome    http://codeforces.com/problemset/problem/805/B /* 题意字符串中不能有长度为三的回文串,且c数量最少 */ ...

  6. Saiku导出excel指标列无线条以及0与空值显示问题(三十二)

    Saiku导出excel指标列无线条以及0与空值显示问题 描述: 数据库中字段值为0 ,与数据库中字段值为 null 时 ,saiku会将为0 以及为 null 的数据都不展示出来,但是我们其实希望数 ...

  7. SharePoint通过IP地址访问

    问题:SP站点通过计算机名称可以访问,但不能通过IP地址访问 解决方案:打开SharePoint2010管理中心>应用程序管理>配置备用访问映射>编辑公用 URL 备用访问映射集:选 ...

  8. STL之set篇

    insert为插入.set_intersection求交集,set_union求并集,是属于algorithm里的函数. 例题有 PAT甲级1063 #include<iostream> ...

  9. jsp%不能解析

    做一个传值问题时 遇到错误 百度了一下是百分号不能解析,实在搞不明白为什么,以前这样做好好的,这次就不行了,不知道为什么,后来偶然一次把标签删了 错误居然没了,难道struts2的这个标签不支持这样传 ...

  10. CSS——层级

    层级问题:选中的盒子显示的效果并不完整,右边的边框并没有显示红色,原因是其右边的盒子压了它的边框. <!DOCTYPE html> <html lang="en" ...