题目链接: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. 引用so动态链接库的方法

    from ctypes import cdll lib = cdll.LoadLibrary('/home/zhengli/test/test.so') lib.func() 总结: 1.引用ctyp ...

  2. LNMP一键安装包+Thinkphp搭建基于pathinfo模式的路由

    LNMP一键安装包是一个用Linux Shell编写的可以为CentOS/RadHat/Fedora.Debian/Ubuntu/Raspbian/Deepin VPS或独立主机安装LNMP(Ngin ...

  3. 递归,装饰器,python常用内置方法

    **递归**        def calc(n):            print(n)            if int(n / 2) == 0:  条件判断                r ...

  4. 【Java】 java判断字符串是否为空的方法总结

    以下是java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equals(s));方法二: ...

  5. Spring Boot实现通用的接口参数校验

    Spring Boot实现通用的接口参数校验 Harries Blog™ 2018-05-10 2418 阅读 http ACE Spring App API https AOP apache IDE ...

  6. Tomcat发布项目的几种方式

    如何在浏览器访问一个xml文件 拷贝这个文件到webapps/ROOT底下, 在浏览器里面访问 直接把tomcat/webapps/ROOT目录下 浏览器访问http://localhost:8080 ...

  7. Apache Hadoop集群离线安装部署(二)——Spark-2.1.0 on Yarn安装

    Apache Hadoop集群离线安装部署(一)——Hadoop(HDFS.YARN.MR)安装:http://www.cnblogs.com/pojishou/p/6366542.html Apac ...

  8. String转list

    String l = "63, 47, 51, 35, 36, 52, 37, 53, 38, 54, 39, 55, 40, 56, 41, 57, 42";List<In ...

  9. compiz隐藏最大化窗口标题栏

    xfwm换了compiz试试,还行,挺方便.就是这个隐藏最大化窗口的标题栏没有现成的ui设置项,google到如下解决方案: 修改后立即生效. https://planetkris.com/2009/ ...

  10. Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)

    转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...