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

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn = 10100;
struct abc{ int start, end; double path; }node[maxn];
bool cmp(const abc&a, const abc&b){ return a.path < b.path; }
double x[maxn], y[maxn], z[maxn], r[maxn];
int father[maxn];
int find(int x)
{if (x != father[x]) father[x] = find(father[x]);return father[x];
}
int main()
{int n, i, j;while (~scanf("%d", &n)){if (n == 0) break;int tot = 0;for (i = 1; i <= n; i++) scanf("%lf%lf%lf%lf", &x[i], &y[i], &z[i], &r[i]);for (i = 0; i <= n; i++) father[i] = i;for (i = 1; i <= n; i++){for (j = i + 1; j <= n; j++){node[tot].start = i;node[tot].end = j;double tt = 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 (tt <= r[i] + r[j]) node[tot].path = 0;else node[tot].path = tt - r[i] - r[j];tot++;}}double ans = 0;sort(node, node + tot, cmp);for (i = 0; i < tot; i++){int xx = find(node[i].start);int yy = find(node[i].end);if (xx != yy){father[xx] = yy;ans = ans + node[i].path;}}printf("%.3lf\n", ans);}return 0;
}

转载于:https://www.cnblogs.com/zufezzt/p/4482354.html

zoj 1718 poj 2031 Building a Space Station相关推荐

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

    题目链接:http://poj.org/problem?id=2031点击打开链接 Building a Space Station Time Limit: 1000MS   Memory Limit ...

  2. POJ 2031 Building a Space Station

    题目链接:http://poj.org/problem?id=2031 题目意思是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能够相互连通.如果两个球有重叠的部分则算为已连通,无需再 ...

  3. pku 2031 Building a Space Station 最小生成树+精度控制

    http://poj.org/problem?id=2031 题意就是给你n个球的(球心以及半径),然后求最小生成树就欧了,这里的关键部分是对于重复的球的路径长度的处理 #include <io ...

  4. POJ_2031 Building a Space Station

    Building a Space Station 链接 POJ_2031 Building a Space Station Describe You are a member of the space ...

  5. poj2031 Building a Space Station

    题目链接:http://poj.org/problem?id=2031 题意:给你n个球,让你用最小的花费,把这n个球联通,如果两个球相交,就默认联通,否者连接这两个球的花费就是,球面之间的最短距离, ...

  6. I. Space Station(hash记忆化+dp)

    <文章>陆游 文章本天成,妙手偶得之. 粹然无疵瑕,岂复须人为. 君看古彝器,巧拙两无施. 汉最近先秦,固已殊淳漓. 胡部何为者,豪竹杂哀丝. 后夔不复作,千载谁与期? I. Space ...

  7. HDU 1815, POJ 2749 Building roads(2-sat)

    HDU 1815, POJ 2749 Building roads 题目链接HDU 题目链接POJ 题意: 有n个牛棚, 还有两个中转站S1和S2, S1和S2用一条路连接起来. 为了使得随意牛棚两个 ...

  8. 【POJ 1788 --- Building a New Depot】

    [POJ 1788 --- Building a New Depot] Description Advanced Cargo Movement, Ltd. is successfully expand ...

  9. 油田(zoj 1709, poj 1562)

    油田(zoj 1709, poj 1562) [题目描述] GeoSurvComp 地质探测公司负责探测地下油田. 每次 GeoSurvComp 公 司都是在一块长方形的土地上来探测油田. 在探测时, ...

最新文章

  1. PHP7.3中fileinfo怎么安装与开启
  2. python pip换源方法
  3. ORACLE分区表删除分区数据
  4. MYSQL——常用运算符和函数
  5. php 构造函数 链接数据库,构造函数在php中的使用方法(附示例)-php教程
  6. php考试倒计时提交系统,AJAX_基于Ajax技术实现考试倒计时并自动提交试卷,1.概述在开发网络考试系统 - phpStudy...
  7. java magic number_避免JDBC查询中的CheckStyle magic number错误
  8. 【hdu2089】不要62
  9. 大数据_Hbase-shell命令_操作hbase_完成对表的增删改查---Hbase工作笔记0005
  10. 有哪些问题应该得到解决?
  11. 计算机html二级难度,计算机二级考试越来越难的实锤!真实数据告诉你到底难在哪里?...
  12. Android 中关于Cursor类的介绍
  13. idea怎么给方法快速添加注释_生完孩子胸部下垂怎么办?来看快速矫正的方法
  14. 手机号识别轻松对着号码扫一扫就录入了
  15. 蓝牙数字密钥建立在过去实践的基础上, 以创造更安全的未来
  16. 注册公司选小规模还是一般人?四种判别方式讲得明明白白
  17. 番茄todo服务器维护,番茄ToDo:克服“拖延症”必备高效神器!
  18. linux双网卡配置两个ip,centos双线双ip配置,Windows双网卡双ip配置
  19. Problem - 1077E - E. Thematic Contests(暴力+二分)
  20. 多模态训练如何平衡不同模态

热门文章

  1. 青海大学计算机考研调剂,青海大学2020年硕士研究生招生调剂公告
  2. JAVA转smali软件_Java2Smali(Java代码转Smali工具)
  3. python创造订单失败_使用Python API创建新订单,get AttributeError:“str”对象没有属性“iteritems”...
  4. mysql重复你数据标识_MySQL 处理重复数据
  5. idea自动整理代码快捷键_MDK进阶使用教程,快捷启动任意软件,自动整理格式化代码,方便代码整理可以很好 的提高效率...
  6. android studio 手把手叫你NDK开发环境搭建及基础使用
  7. java rails orm_php 模拟 rails 中的 ActionRecord 的 ORM (一)
  8. python黑网站_python
  9. 语义分割和实例分割_2019 语义分割指南
  10. cron一点半到两点半之间每分钟_分辨率,定位精度,重复定位精度三者之间有什么关系?...