poj 2031Building a Space Station(几何判断+Kruskal最小生成树)
/*
最小生成树 + 几何判断
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最小生成树)的更多相关文章
- poj 2031--Building a Space Station(prim)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6064 Accepte ...
- poj 2031Building a Space Station
http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...
- POJ Building a Space Station 最小生成树
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15664 Accepted: 6865 Description You ...
- POJ-2031 Building a Space Station (球的最小生成树)
http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...
- poj Building a Space Station
http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...
- 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 ...
- POJ 2031 Building a Space Station【经典最小生成树】
链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5173 Accepte ...
- Building a Space Station(kruskal,说好的数论呢)
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3820 Accepted: 1950 Description You a ...
随机推荐
- 最新Ubuntu10.10 更新源
Ubuntu10.10这个版本真的很老了,官方N多年前早已不再支持更新软件源了. 目前可用的有中科大镜像更新源. 中科大Ubuntu 10.10源列表: deb http://mirrors.ustc ...
- windows 录音程序(二)
(二)录音流程 Waveform APIs,流程如下: a.打开录音设备waveInOpen; b.准备wave数据头waveInPrepareHeader; c.准备数据块waveInAddBuff ...
- idea中maven报错:无效的目标发行版: 1.8
1.project.pom中修改版本 <maven.compiler.source>1.7</maven.compiler.source><maven.compiler. ...
- Sql Servicer 复习笔记(1) 存储过程分布
第一步:创建表 declare @countInt int declare @age int ) begin ),@countInt), @age,'中国北京') ; ; ) begin ; end ...
- LintCode 111 Climbing Stairs
这道题参考了这个网址: http://blog.csdn.net/u012490475/article/details/48845683 /* 首先考虑边界情况,当有1层时,有一种方法. 然后再看2层 ...
- 解决ViewPage中嵌套有ListView或者滑动手势等造成滑动的冲突
public class ViewPagerCompat extends ViewPager { //mViewTouchMode表示ViewPager是否全权控制滑动事件,默认为false,即不控制 ...
- 练习1-12:编写一个程序,以每行一个单词的形式打印其输入(C程序设计语言 第2版)
#include <stdio.h> #define NOT_BLANK 1 #define BLANK 0 main() { int c; int last_ch = NOT_BLANK ...
- python学习GUIwxpython不支持中文输出入的问题
# -*- coding: utf8 -*- import wx def load(event): file = open(filename.GetValue()) contents.SetValue ...
- iOS直播直播,头都大了
随着直播市场的火热,市场大军都逐步进入直播市场 ,腾讯旗下的NOW直播也不例外 先说说直播设计底层 一 .流媒体 1 - 伪流媒体 1.1 扫盲:边下载边播放 1.2 伪流媒体:视频不是实时播放的,先 ...
- 解剖SQLSERVER 第六篇 对OrcaMDF的系统测试里避免regressions(译)
解剖SQLSERVER 第六篇 对OrcaMDF的系统测试里避免regressions (译) http://improve.dk/avoiding-regressions-in-orcamdf-b ...