题目链接:http://poj.org/problem?id=2031

题意:修建太空站每个舱之间的走廊。每个舱都是球体。给出n个舱的三维空间坐标以及球体半径。如果球体之间接触或者相接,就不用修走廊。让你求最短走廊的长度。

题解:有点点坑这个题。。改了好久。。这里的存储其实是 $len(a,b) - r_a - r_b$ 求一下这个存储再以Prim求解即可。注意精度。

代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
double mp[maxn][maxn];
double dis[maxn];
bool vis[maxn];
int n; struct node{
double x;
double y;
double z;
double r;
}; node cir[maxn]; double dist(node a,node b){
double diss = (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) + (a.z -b.z) * (a.z - b.z);
return sqrt(diss) - a.r - b.r;
} double prim(){
double ans = ;
int k;
double minn ;
for(int i = ; i <= n ; i++){
dis[i] = inf ;
vis[i] = false ;
}
dis[] = ;
for(int i = ; i <= n ; i++){
minn = inf ;
k = ;
for(int j = ; j <= n ; j++){
if(minn > dis[j] && !vis[j]){
minn = dis[j] ;
k = j ;
}
}
if(minn >= inf)
return - ;
ans += minn ;
vis[k] = true ;
for(int j = ; j <= n ; j++){
if(!vis[j] && dis[j] > mp[k][j])
dis[j] = mp[k][j] ;
}
}
return ans ;
} int main(){
while(cin>>n && n){
for(int i = ; i <= n ;i++){
cin>>cir[i].x>>cir[i].y>>cir[i].z>>cir[i].r;
}
memset(mp,,sizeof(mp));
for(int i = ; i < n; i++){
for(int j = i+; j <= n ;j++){
if(dist(cir[i],cir[j]) < eps){
mp[i][j] = mp[j][i] = ;
}
else{
mp[i][j] = mp[j][i] = dist(cir[i],cir[j]);
}
}
}
/*
for(int i = 1; i <= n; i++){
for(int j = 1 ; j <= n ;j++){
cout<<mp[i][j]<<" ";
}
cout<<endl;
}*/
double ans = prim();
if(ans != -){
printf("%.3lf\n",ans);
} } return ;
}

【POJ】2031 Building a Space Station的更多相关文章

  1. POJ 2031 Building a Space Station【经典最小生成树】

    链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

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

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

  3. POJ 2031 Building a Space Station

    3维空间中的最小生成树....好久没碰关于图的东西了.....              Building a Space Station Time Limit: 1000MS   Memory Li ...

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

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

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

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

  6. POJ - 2031 Building a Space Station 三维球点生成树Kruskal

    Building a Space Station You are a member of the space station engineering team, and are assigned a ...

  7. POJ 2031 Building a Space Station【最小生成树+简单计算几何】

    You are a member of the space station engineering team, and are assigned a task in the construction ...

  8. POJ 2031 Building a Space Station (计算几何+最小生成树)

    题目: Description You are a member of the space station engineering team, and are assigned a task in t ...

  9. POJ 2031 Building a Space Station (prim裸题)

    Description You are a member of the space station engineering team, and are assigned a task in the c ...

随机推荐

  1. vbox出现Failed to opencreate the internal network错误,无法启动虚拟机

    vbox出现Failed to opencreate the internal network错误,无法启动虚拟机 标签(空格分隔): 未分类 问题 Failed to open/create the ...

  2. 火狐foxyproxy + burp

    下载 火狐foxyproxy 和 burp 两个代理ip端口填写一致 如果对于公司有正向代理服务器,则需要配置burp的上游代理 对于IE浏览器的代理是windows操作系统的全局代理,在ie配置代理 ...

  3. python基础【第五篇】

    python第三节 1.整型及布尔值 1.1 进制转换 十进制 ----二进制 二进制 ----十进制 8421方法与普通计算 python中十进制转二进制示例:bin(51)>>> ...

  4. Android Service完全解析(下)

    转载http://blog.csdn.net/guolin_blog/article/details/9797169 在上一篇文章中,我们学习了Android Service相关的许多重要内容,包括S ...

  5. Java中如何实现序列化,有什么意义?

    序列化就是一种用来处理对象流的机制,所谓对象流也就是将对象的内容进行流化.可以对流化后的对象进行读写操作,也可将流化后的对象传输于网络之间.序列化是为了解决对象流读写操作时可能引发的问题(如果不进行序 ...

  6. rest framework之渲染器

    一.内置渲染器 REST框架包括许多内置的Renderer类,它们允许你使用各种媒体类型返回响应.还支持定义你自己的自定义渲染器. 内置渲染器的使用 1.全局设置 可以使用DEFAULT_RENDER ...

  7. spark window本地运行wordcount错误

    在运行本地运行spark或者hadoop代码时可能会遇到一下三种问题   1.Exception in thread "main" java.lang.UnsatisfiedLin ...

  8. linux crontab 计划任务脚本

    在LINUX中你应该先输入crontab -e,然后就会有个vi编辑界面,再输入0 3 * * 1 /clearigame2内容到里面 :wq 保存退出. 在LINUX中,周期执行的任务一般由cron ...

  9. echarts 报表使用

    下载echats后,将下包中的js引入项目,\echarts-2.2.7\echarts-2.2.7\build\dist //在页面中建立宽高的区域,用来显示报表 <div style=&qu ...

  10. Java中Map集合的基本功能

    Map基本方法: put方法: remove方法: isEmpty方法: . clear方法: containsKey方法: containsValue方法 size方法: get方法: keySet ...