题目链接: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. 100个常用js代码(转载)

    作者:小萧ovo链接:https://zhuanlan.zhihu.com/p/23076321来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. JavaScript定点 ...

  2. jmeter 不同线程组之间传递变量2

    方法1  通过变量传递参数: 第一个脚本: HTTP Request_新建出差申请单_登录,关联出参数token.companyId.userId.userName 1.添加后置处理器:BeanShe ...

  3. fedora 25重新安装引导

    引导区被其他系统给覆盖了,重新安装引导 grub2-install /dev/sdb GRUB_SAVEDEFAULT=true BIOS grub2-mkconfig -o /boot/grub2/ ...

  4. python 包管理工具 pip 的配置

    近几年来,python的包管理系统pip 越来越完善, 尤其是对于 windows场景下,pip大大改善了python的易用性. https://www.cnblogs.com/yvivid/p/pi ...

  5. vue+Mint-ui实现登录注册

    创建一个组件:注册组件 (register/index.vue.script.js.style.scss,register/header) 注册路由 router/index.js { path: ' ...

  6. Spring学习笔记(4)——IoC学习

    IoC理论的背景我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 图1:软件系统中耦合的对象 如果我们打开机械式手表 ...

  7. 理解 Activity.runOnUiThread

    在开发 Android 应用的时候我们总是要记住应用主线程. 主线程非常繁忙,因为它要处理绘制UI,响应用户的交互,默认情况下执行我们写下的大部分代码. 好的开发者知道他/她需要将重负荷的任务移除到工 ...

  8. python字典拼接方法

    python的dict拼接有多种方法,其中一种很好用而且速度非常快: x = {**a, **b} 效果等价于: x = a.copy() x.update(b) 注意update()是没有返回值的 ...

  9. react todelist

    1.点击按钮提交,新增对象 buttonChange() { this.setState({ //展开运算符...this.state.list,生成一个全新的数组 // list:[...this. ...

  10. poj 3294 后缀数组+二分

    题目大意: 给定n个字符串,求出现在不小于k个字符串中的最长子串 基本思路: 二分长度,统计个数,一般套路,就是这个跟说好的不一样啊,我非得开2倍才不re,真他妈不爽,先二分找出长度,然后根据长度输出 ...