/*
最小生成树 + 几何判断
Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int f[];
struct ball{
double x, y, z, r;
}; struct connect{
double dist;
int a, b;
}; connect c[]; ball b[]; bool cmp(connect a, connect b){
return a.dist < b.dist;
}
int n; int getFather(int x){
return x==f[x] ? x : f[x]=getFather(f[x]);
} int Union(int a, int b){
int fa=getFather(a), fb=getFather(b);
if(fa!=fb){
f[fa]=fb;
return ;
}
return ;
} int main(){
int i, j;
while(scanf("%d", &n) && n){
for(i=; i<=n; ++i)
scanf("%lf%lf%lf%lf", &b[i].x, &b[i].y, &b[i].z, &b[i].r);
int cnt=;
for(i=; i<n; ++i)
for(j=i+; j<=n; ++j){
double d = sqrt((b[i].x-b[j].x)*(b[i].x-b[j].x) + (b[i].y-b[j].y)*(b[i].y-b[j].y) + (b[i].z-b[j].z)*(b[i].z-b[j].z))
- (b[i].r + b[j].r);
c[cnt].dist= d< ? : d;
c[cnt].a=i;
c[cnt++].b=j;
}
sort(c, c+cnt, cmp);
double minSum=0.0;
for(i=; i<=n; ++i)
f[i]=i;
for(i=; i<cnt; ++i){
if(Union(c[i].a, c[i].b))
minSum+=c[i].dist;
}
printf("%.3lf\n", minSum);
}
return ;
}

poj 2031Building a Space Station(几何判断+Kruskal最小生成树)的更多相关文章

  1. poj 2031--Building a Space Station(prim)

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

  2. poj 2031Building a Space Station

    http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...

  3. POJ Building a Space Station 最小生成树

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15664   Accepted: 6865 Description You ...

  4. POJ-2031 Building a Space Station (球的最小生成树)

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

  5. poj Building a Space Station

    http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...

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

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

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

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

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

  9. Building a Space Station(kruskal,说好的数论呢)

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3820   Accepted: 1950 Description You a ...

随机推荐

  1. 20145301&20145321&20145335实验五

    20145301&20145321&20145335实验五 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验五

  2. 【C-循环结构】

    C语言提供了多种循环语句,可以组成各种不同形式的循环结构: 用goto语句和if语句构成循环: 用while语句: 用do-while语句: 用for语句: 一.goto语句 goto语句是一种无条件 ...

  3. Tableau:数据可视化之急速BI

    1.我们通过数据可视化,是为了从数据中寻找什么呢?三个方面:模式.关系和异常.不管图形表现的是什么,我们都要留心观察这三者.

  4. mongoDB研究笔记:写关注

    对于某些应用程序来说,写关注是重要的.它能判断哪些写操作成功写入了,哪些失败了,对于失败的操作,驱动程序能返回错误,由应用程序决定怎么处理.如果没有写关注,应用程序发送一个写操作到socket后,就不 ...

  5. note of introduction of Algorithms(Lecture 3 - Part1)

    Lecture 3(part 1) Divide and conquer 1. the general paradim of algrithm as bellow: 1. divide the pro ...

  6. 作业三(代码规范、代码复审、PSP)

    1.代码规范: 我支持代码要有规范,理由如下. (1).艺术是一个很带有个人风格的学科,天马行空才能凸显出自己的价值.但不要忘了,会艺术的不是生下来就会艺术, 他也需要按照前辈的步骤一步一步的学习基础 ...

  7. PC远程调试移动设备

    我们在移动端进行前端开发时,会遇到一个让人头痛但不得不面对的问题——调试. 在 PC 机器上,我们有功能强大的 Chrome DevTools.Firebug,即便是老版本的 IE ,我们也可以安装微 ...

  8. XSS零碎指南

    该文章是本人两天的学习笔记,共享出来,跟大家交流.知识比较零散,但是对有一定 JS 基础的人来说,每个小知识都有助于开阔你的 Hack 视角.首先声明,本文只是 XSS 攻击的冰山一角,读者自行深入研 ...

  9. 【原创】我是怎么从零开始教女同学进行php开发的(4)

    周末给自己放了一个小假,周五晚上跟同学出去吃饭,周六又休息了一天,直到周日才坐到电脑前面码字. 本来说好周末这两天把之前三篇的代码根据评论中的建议好好修改一下的,顺便认真系统地学习一遍HTML基础.结 ...

  10. [stm32] SIM808模块之发短信\GPS\TCP\HTTP研究

    SIM8008是四频模块,全球可用.含有TTL电平接口等接口,能够实现发短信.打电话.GPRS传输数据.GPS等功能.[正版资料请找beautifulzzzz·博客园] 一些细节: >> ...