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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 1e5+100;
struct node
{int u,v;double c;node() {}node(int _u,int _v,double _c){u = _u;v = _v;c = _c;}bool operator < (const node &b)const{return c<b.c;}
}res[maxn];
struct point
{double x,y,z,r;
}a[105];
int fa[105];
double dis(point p1,point p2)
{return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}
int getfa(int x)
{if(fa[x]==x)return fa[x];return fa[x] = getfa(fa[x]);
}
int main(void)
{int n;while(~scanf("%d",&n)&&n){for(int i=1;i<=n;i++){scanf("%lf %lf %lf %lf",&a[i].x,&a[i].y,&a[i].z,&a[i].r);fa[i] = i;}int cnt = 0;for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){double d = dis(a[i],a[j])-a[i].r-a[j].r;res[cnt++] = node(i,j,max(d,0.0));}}double ans = 0;sort(res,res+cnt);for(int i=0;i<cnt;i++){int t1 = getfa(res[i].u);int t2 = getfa(res[i].v);if(t1!=t2){ans += res[i].c;fa[t1] = t2;}}printf("%.3f\n",ans);}return 0;
}

poj2031 Building a Space Station相关推荐

  1. POJ_2031 Building a Space Station

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

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

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

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

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

  4. POJ 2031 Building a Space Station

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

  5. zoj 1718 poj 2031 Building a Space Station

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

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

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

  7. Building a Space Station--POJ 2031

    1.题目类型:计算几何,最小生成树. 2.解题思路:(1)获得所有点路径长度的矩阵map[][]:(2)利用Prim算法求解最小生成树. 3.注意事项:数学操作,中间值全部用double保存. 4.实 ...

  8. poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

    1 /* 2 最小生成树 + 几何判断 3 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 4 */ 5 #include<iostream ...

  9. 2019 ICPC Asia Nanjing Regional I. Space Station题解

    文章目录 [题目链接] [前言] [题目大意] [解题思路] 一.优先暴力 二.记忆化 三.unordered_map以及思维优化 四.乘法逆元(拓展内容) [后记] [题目链接] https://n ...

最新文章

  1. 一场科技盛宴,一次“盈”满天下 安创成长营五期Demo Day完美收官
  2. 谈谈浅拷贝和深拷贝的区别,以及实现的方法
  3. 【移动开发】Android中三种超实用的滑屏方式汇总(ViewPager、ViewFlipper、ViewFlow)...
  4. mysql怎么滤空_《MySQL 入门教程》第 08 篇 过滤条件
  5. openFeign 服务接口的调用01——概述
  6. WF:要想绑到两个活动的属性值---依赖属性的定义方法
  7. 从源码深处体验Spring核心技术--基于Xml的IOC容器的初始化
  8. Angular 如何自定义 pipe 管道以及参数传递问题
  9. maven配置junit5_JUnit 5和Selenium –改善项目配置
  10. c语言队列原理的实现,c印记(十二):队列queue原理与实现
  11. Unicode 和 UTF-8 之间的关系
  12. 九、Promises
  13. 四菱天线怎么加强_关于自制电视四菱天线材料好坏和买连接线和转接头问题
  14. 「数据架构」什么是实体关系图(ERD)?
  15. 长大后自卑的孩子,大多出自这几种家庭,别不当回事(给已经做父母或未来即将为人父母的你)
  16. 用jsp的mvc模式的新闻发布系统_网易内部倡导用昵称代替哥姐总等称呼;TCL大股东误操作卖出500万股;Ant Design 4.6.2 发布| 极客头条...
  17. egg Cannot find module ‘diagnostics_channel‘
  18. 配置windows 静态IP地址
  19. python 微信机器人教程_Python创建微信机器人(附赠Python视频教程)
  20. chmod 命令详细用法

热门文章

  1. 快手直播伴侣电脑版屏幕过大解决方案
  2. 干货 | 数字经济创新创业——网络安全
  3. URL编码和解码 C++类URL编码和解码使用技巧
  4. 买英伟达RTX 30 系显卡送《穿越火线》大礼包,你心动了吗?
  5. 微信小程序统一设置所有页面背景色
  6. 【Davinci开发】:MCAL模块导入(之:ICU模块)
  7. C8051F410看门狗的使用方法
  8. 华为手机灵敏度设置_华为手机还可以这样玩,让你灵敏度提高,你服不服!
  9. wps js宏写一个可以批量合并Excel文件表格数据的工具
  10. 这个 17 岁的黑客天才,破解了第一代 iPhone!