poj 2031
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 200
double co(double a,double b) {
return (a-b)*(a-b);
}
struct node {
double x,y,z,r;
}a[N];
struct nodee{
double len;
int x,y;
}map[N*N];
int pre[N];
int find(int x) {
if(x!=pre[x])
pre[x]=find(pre[x]);
return pre[x];
}
int cmp(const void *b,const void *c) {
return (*(struct nodee *)b).len>(*(struct nodee *)c).len?1:-1;
}
int main() {
double r,sum;
int n,i,j,k,e,w;
while(scanf("%d",&n),n) {
for(i=1;i<=n;i++)
pre[i]=i;
for(i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z,&a[i].r);
k=0;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++) {
r=sqrt(co(a[i].x,a[j].x)+co(a[i].y,a[j].y)+co(a[i].z,a[j].z));
map[k].x=i;
map[k].y=j;
if(r<=a[i].r+a[j].r)
map[k].len=0;
else
map[k].len=r-(a[i].r+a[j].r);
k++;
}
qsort(map,k,sizeof(map[0]),cmp);
j=1;sum=0;
for(i=0;i<k&&j<n;i++) {
e=find(map[i].x);
w=find(map[i].y);
if(e!=w) {
pre[e]=w;
j++;
sum+=map[i].len;
}
}
printf("%.3f\n",sum);
}
return 0;
}
poj 2031的更多相关文章
- POJ 2031 prim
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4400 Accepted: 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 ...
- poj 2031 Building a Space Station(prime )
这个题要交c++, 因为prime的返回值错了,改了一会 题目:http://poj.org/problem?id=2031 题意:就是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能 ...
- POJ - 2031 Building a Space Station(计算几何+最小生成树)
http://poj.org/problem?id=2031 题意 给出三维坐标系下的n个球体,求把它们联通的最小代价. 分析 最小生成树加上一点计算几何.建图,若两球体原本有接触,则边权为0:否则边 ...
- (最小生成树) Building a Space Station -- POJ -- 2031
链接: http://poj.org/problem?id=2031 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6011 ...
- 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 【PRIME】
题目链接 http://poj.org/problem?id=2031 题意 给出N个球形的 个体 如果 两个个体 相互接触 或者 包含 那么 这两个个体之间就能够互相通达 现在给出若干个这样的个体 ...
- 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 ...
- poj 2031 Building a Space Station【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
- zoj 1718 poj 2031 Building a Space Station
最小生成树,用了Kruskal算法.POJ上C++能过,G++不能过... 算出每两个圆心之间的距离,如果距离小于两半径之和,那么这两个圆心之间的距离直接等于0,否则等于距离-R[i]-R[j]. # ...
随机推荐
- POJ 2195 Going Home 最小费用流
POJ2195 裸的最小费用流,当然也可以用KM算法解决,但是比较难写. 注意反向边的距离为正向边的相反数(因此要用SPFA) #include<iostream> #include< ...
- bzoj4821
线段树 这题真是无聊 把式子拆开,然后可知维护xi,yi,xi^2,xi*yi,重点在于标记下传,当我们进行2号操作时,直接累加进答案和标记即可,进行3号操作时,update时先把自己这层赋值成要改变 ...
- codevs1369 xth 砍树(线段树)
1369 xth 砍树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在一个凉爽的夏夜,xth 和 rabbi ...
- 【学习笔记】线段树—扫描线补充 (IC_QQQ)
[学习笔记]线段树-扫描线补充 (IC_QQQ) (感谢 \(IC\)_\(QQQ\) 大佬授以本内容的著作权.此人超然于世外,仅有 \(Luogu\) 账号 尚可膜拜) [学习笔记]线段树详解(全) ...
- HTML--文本输入框、密码输入框
当用户要在表单中键入字母.数字等内容时,就会用到文本输入框.文本框也可以转化为密码输入框. 语法: <form> <input type="text/password&qu ...
- jmeter 3.x plugins 的使用
JMeter Plugins 一直以来,JMeter Plugins为我们提供了很多高价值的JMeter插件,比如: 用于服务器性能监视的PerfMon Metrics Collector 用于建立压 ...
- [转]asp.net MVC 常见安全问题及解决方案
本文转自:http://www.cnblogs.com/Jessy/p/3539564.html asp.net MVC 常见安全问题及解决方案 一.CSRF (Cross-site request ...
- MVC系列学习(八)-分布视图
1.本次学习实例 1.1.建议:为了尽可能让项目简单,就新建一个空的mvc项目,同时添加任何视图不用模板页 1.2注意:在添加LoginPart的分部视图时,要记得沟一个沟 2.项目代码,如下 总共三 ...
- AIDL跨进程通信报Intent must be explicit
在Android5.0机子上采用隐式启动来调试AIDL时,会出现Intent must be explicit的错误,原因是5.0的机子不允许使用隐式启动方式,解决的方法是:在启动intent时添加i ...
- elasticsearch——海量文档高性能索引系统
elasticsearch elasticsearch是一个高性能高扩展性的索引系统,底层基于apache lucene. 可结合kibana工具进行可视化. 概念: index 索引: 类似SQL中 ...