#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=1e5;
struct edge{
int a,b;
double w;
}e[N];
double x[N],y[N],z[N],r[N];
int n,tot,p[N];
bool cmp(edge a,edge b)
{
return a.w<b.w;
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
void kruskal()
{
double sum=;
for(int i=;i<tot;i++)
{
int a=find(e[i].a);
int b=find(e[i].b);
double w=e[i].w;
if(a!=b)
{
sum+=w;
p[a]=b;
}
}
printf("%.3f\n",sum);
}
int main()
{
while(cin>>n&&n)
{
for(int i=;i<n;i++)
cin>>x[i]>>y[i]>>z[i]>>r[i];
for(int i=;i<=n;i++)
p[i]=i;
tot=;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++)
{
double t=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]));
if(r[i]+r[j]>=t)
e[tot++]={i,j,};
else
e[tot++]={i,j,t-r[i]-r[j]};
}
sort(e,e+tot,cmp);
kruskal(); }
return ;
}

Building a Space Station POJ - 2031 三维最小生成树,其实就是板子题的更多相关文章

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

  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. (最小生成树) Building a Space Station -- POJ -- 2031

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

  4. C - Building a Space Station - poj 2031

    空间站是有一些球状的房间组成的,现在有一些房间但是没有相互连接,你需要设计一些走廊使他们都相通,当然,有些房间可能会有重合(很神奇的样子,重合距离是0),你需要设计出来最短的走廊使所有的点都连接. 分 ...

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

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

  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 最小生成树

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

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

    Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...

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

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

随机推荐

  1. 06-HTML

    今日知识 1. HTML基本语法 2. 特殊符号表示 3.总结 HTML 1. Hyper Text Mark Language 超文本标记语言 * 超文本: * 超文本是用超链接的方法,将各种不同空 ...

  2. lwip netbuf

    lwip2.0.2 netbuf_new——分配netbuf结构体的内存. netbuf_alloc,分配netbuf中pbuf内存(pbuf_alloc中PBUF_RAM类型,包括pbuf结构体和p ...

  3. prometheus operator(Kubernetes 集群监控)

    一.Prometheus Operator 介绍 Prometheus Operator 是 CoreOS 开发的基于 Prometheus 的 Kubernetes 监控方案,也可能是目前功能最全面 ...

  4. 5.7.20 多实例——MGR部署实战

    数据库 | MySQL:5.7.20 多实例——MGR部署实战 MGR介绍 基于传统异步复制和半同步复制的缺陷——数据的一致性问题无法保证,MySQL官方在5.7.17版本正式推出组复制(MySQL ...

  5. Iptables netstat 防御简单dos攻击

    DoS攻击或者DDoS攻击是试图让机器或者网络资源不可用的攻击.这种攻击的攻击目标网站或者服务通常是托管在高防服务器比如银行,信用卡支付网管,甚至根域名服务器,DOS攻击的实施通常迫使目标重启计算机或 ...

  6. Windows远程连接Ubuntu上的MySQL数据库

    原因:mysql安装好后,默认监听3306端口,并且只允许localhost访问,只允许root用户在localhost上登录.   我的环境:                 Ubuntu16.04 ...

  7. Redis 为什么这么快?

    1. 纯内存操作,肯定快 数据存储在内存中,读取的时候不需要进行磁盘的 IO 2. 单线程,无锁竞争损耗 单线程保证了系统没有线程的上下文切换 使用单线程,可以避免不必要的上下文切换和竞争条件,没有多 ...

  8. 使用 Apache James 3.3.0(开源免费) 搭建内网电子邮件服务器(基于 Windows + Amazon Corretto 8)

    电子邮件服务器,对于很多公司,都是需要的. 虽然现在很多人,使用 QQ .微信进行一对一的工作沟通,使用QQ 群.微信群进行多人沟通,但这些即时聊天工具,与电子邮件相比,仍有很多不足: a. 电子邮件 ...

  9. 安卓接入融云IM连接不上??

    融云初始化失败?融云连接失败??连接回调方法不执行???不可能的,就那么几行代码,怎么会有错. 1.项目gradle里添加融云maven仓库 maven {url "https://dl.b ...

  10. css选择器四大类:基本、组合、属性、伪类

    什么是选择器?选择器的作用是通过它可以找到元素,把css样式传递给元素!css选择器主要分为:基本选择器.属性选择器.组合选择器与伪类选择器四个大类! css基本选择器 基本选择器又分为:*通配符.标 ...