POJ2031 Building a Space Station 2017-04-13 11:38 48人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 8572 | Accepted: 4093 |
Description
The space station is made up with a number of units, called cells. All cells are sphere-shaped, but their sizes are not necessarily uniform. Each cell is fixed at its predetermined position shortly after the station is successfully put into its orbit. It is
quite strange that two cells may be touching each other, or even may be overlapping. In an extreme case, a cell may be totally enclosing another one. I do not know how such arrangements are possible.
All the cells must be connected, since crew members should be able to walk from any cell to any other cell. They can walk from a cell A to another cell B, if, (1) A and B are touching each other or overlapping, (2) A and B are connected by a `corridor', or
(3) there is a cell C such that walking from A to C, and also from B to C are both possible. Note that the condition (3) should be interpreted transitively.
You are expected to design a configuration, namely, which pairs of cells are to be connected with corridors. There is some freedom in the corridor configuration. For example, if there are three cells A, B and C, not touching nor overlapping each other, at least
three plans are possible in order to connect all three cells. The first is to build corridors A-B and A-C, the second B-C and B-A, the third C-A and C-B. The cost of building a corridor is proportional to its length. Therefore, you should choose a plan with
the shortest total length of the corridors.
You can ignore the width of a corridor. A corridor is built between points on two cells' surfaces. It can be made arbitrarily long, but of course the shortest one is chosen. Even if two corridors A-B and C-D intersect in space, they are not considered to form
a connection path between (for example) A and C. In other words, you may consider that two corridors never intersect.
Input
n
x1 y1 z1 r1
x2 y2 z2 r2
...
xn yn zn rn
The first line of a data set contains an integer n, which is the number of cells. n is positive, and does not exceed 100.
The following n lines are descriptions of cells. Four values in a line are x-, y- and z-coordinates of the center, and radius (called r in the rest of the problem) of the sphere, in this order. Each value is given by a decimal fraction, with 3 digits after
the decimal point. Values are separated by a space character.
Each of x, y, z and r is positive and is less than 100.0.
The end of the input is indicated by a line containing a zero.
Output
Note that if no corridors are necessary, that is, if all the cells are connected without corridors, the shortest total length of the corridors is 0.000.
Sample Input
3
10.000 10.000 50.000 10.000
40.000 10.000 50.000 10.000
40.000 40.000 50.000 10.000
2
30.000 30.000 30.000 20.000
40.000 40.000 40.000 20.000
5
5.729 15.143 3.996 25.837
6.013 14.372 4.818 10.671
80.115 63.292 84.477 15.120
64.095 80.924 70.029 14.881
39.472 85.116 71.369 5.553
0
Sample Output
20.000
0.000
73.834
Source
—————————————————————————————————————
题目的意思是在一个三维的空间中给出n个球体,球的球心和半径已知,现在要将所有的球连通起来,两个球的花费是圆心距减去半径和(接触为0),问最小花费
思路:把每个球当做一个点两两建边,求最小生成树
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#define LL long long struct node
{
int u,v;
double w;
} p[100005];
int n,cnt,pre[106]; bool cmp(node a,node b)
{
return a.w<b.w;
}
void init()
{
for(int i=0; i<105; i++)
pre[i]=i;
} int fin(int x)
{
return pre[x]==x?x:pre[x]=fin(pre[x]);
} void kruskal()
{
sort(p,p+cnt,cmp);
init();
double cost=0;
int ans=0;
for(int i=0; i<cnt; i++)
{
int a=fin(p[i].u);
int b=fin(p[i].v);
if(a!=b)
{
pre[a]=b;
cost+=p[i].w;
ans++;
}
if(ans==n-1)
{
break;
}
}
printf("%.3f\n",cost);
} int main()
{
double x[105],y[105],z[105],r[105];
while(~scanf("%d",&n)&&n)
{ for(int i=0; i<n; i++)
scanf("%lf%lf%lf%lf",&x[i],&y[i],&z[i],&r[i]);
cnt=0;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
{
p[cnt].u=i,p[cnt].v=j;
p[cnt++].w=max(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]))-r[i]-r[j],0.0);
}
kruskal();
}
return 0;
}
POJ2031 Building a Space Station 2017-04-13 11:38 48人阅读 评论(0) 收藏的更多相关文章
- HDU1241 Oil Deposits 2016-07-24 13:38 66人阅读 评论(0) 收藏
Oil Deposits Problem Description The GeoSurvComp geologic survey company is responsible for detectin ...
- POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏
A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...
- 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏
在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...
- Segment Tree 分类: ACM TYPE 2014-08-29 13:04 97人阅读 评论(0) 收藏
#include<iostream> #include<cstdio> using namespace std; struct node { int l, r, m; int ...
- HDU1349 Minimum Inversion Number 2016-09-15 13:04 75人阅读 评论(0) 收藏
B - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏
Building Shops Time Limit: 2000/1000 MS ...
- Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...
- Oracle错误IMP-00010: 不是有效的导出文件, 头部验证失败 分类: Oracle 2015-07-09 13:56 20人阅读 评论(0) 收藏
Oracle 11g的dmp备份文件导入到Oracle 10g,出现错误信息: Import: Release 10.2.0.1.0 - Production on 星期四 7月 9 13:47:04 ...
- Eclipse 快捷键大全 分类: C_OHTERS 2014-06-01 13:05 332人阅读 评论(0) 收藏
精选常用: 1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的前几个字母,比如a ...
随机推荐
- 02 - Unit03:注册功能实现
注册功能实现 发送Ajax请求 服务器处理 Ajax回调处理 发送Ajax请求 绑定事件: "注册"按钮的单击事件 获取参数: 用户名/密码/昵称 请求地址: /user/regi ...
- 【路由达人】简单两步搞定小米路由新增功能-DDNS(解析域名地址转向在线工具)
DDNS(Dynamic Domain Name Server)是动态域名服务的缩写! 简单来说目前ISP大多为我们提供动态IP(如ADSL拨号上网),而很多设备或服务需要通过远程访问时需要一个固定的 ...
- FT5X06 如何应用在10寸电容屏
硬件搭起来看现象,如下图: 红色区域是FT5406上报有效数据的范围(1280*600),以左上角为原点 ,X轴方向上报数据的最大值1280,Y轴方向上报的最大数据是600..但是我用的LG的10.1 ...
- emacs之配置3,键盘和鼠标设置
emacsConfig/kbd-mouse-setting.el ;;强制TAB键使用空格 (setq-default indent-tabs-mode nil) ;M-i执行tab-to-tab-s ...
- Linux操作系统多线程信号总结
linux 多线程信号编程总结 linux 多线程信号总结(一) 1. 在多线程环境下,产生的信号是传递给整个进程的,一般而言,所有线程都有机会收到这个信号,进程在收到信号的的线程上下文执行信号处理函 ...
- Java 8 Lambda表达式之方法引用 ::双冒号操作符
双冒号运算符就是java中的方法引用,方法引用的格式是类名::方法名. 这里只是方法名,方法名的后面没有括号“()”.--------> 这样的式子并不代表一定会调用这个方法.这种式子一般是用作 ...
- HDU 2846 Repository(字典树,每个子串建树,*s的使用)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 【POJ】1185 炮兵阵地(状压dp)
题目 传送门:QWQ 分析 看到$ M<=10 $考虑状压. 然后把每行都压一下,那么每个状态相关的就是上一行和上上行的状态. 然后枚举. 然后复杂度最坏是$ O(100 \times 1024 ...
- 新手之:SpringBoot ——Reids主从哨兵整合(CentOS7)
一.Redis主从搭建(一台服务器模拟多个端口) 结构图:) 1.确保安装了Redis,我装在了/opt/redis目录下.可通过"whereis redis-cli"命令查看是否 ...
- 基于git的管理应用程序基线包和版本
由于工作的需要,身为git的小白的我开始研究git相关的命令和操作.结合网上收集和廖雪峰的git教程,记录所学知识点. 相关的效果就不再这里显示了. 首先我们看一下git的常用命令: 常用命令 git ...