题目链接: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. 7.Jmeter 快速入门教程--录制复杂web测试脚本

    Jmeter的功能简单,不需要有脚本语言的编写经验,纯图形界面添加测试场景, 用起来上手很快.但是如果手动添加每一个web(http/https)请求,费时又费力.而且有可能最后手动编写的和实际发的请 ...

  2. jwt token校验获取用户数据

    /** * 用户登录成功之后,获取用户信息 * 1.获取用户id * 2.根据id查询用户 * 3.构建返回值对象 * 4.返回数据 * @return */@RequestMapping(value ...

  3. 程序性能优化之APK大小优化(六)上

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 本篇文章将继续从APK瘦身来介绍APK大小优化:文章主要内容从理 ...

  4. 学习JS基本数据类型与对象的valueOf方法

    https://blog.csdn.net/licheng11403080324/article/details/60128090 https://yq.aliyun.com/articles/399 ...

  5. mybatis 教程(mybatis in action)

    目录简介: 一:开发环境搭建二:以接口的方式编程 三:实现数据的增删改查 四:实现关联数据的查询 五:与spring3集成(附源码) 六:与Spring MVC 的集成 七:实现mybatis分页(源 ...

  6. bzoj4544 椭圆上的整点

    我会所有推理..... Q1:真的这么暴力的统计答案? Q2:蜜汁统计答案.... Q3:为什么不考虑3在不同的位置的情况

  7. 进程之间的通信AIDL

    远程端: package cn.itcast.aidl; //AIDL //首先建立AIDL文件,有点和接口类似,建立好AIDL文件后, //会在gen文件夹下自动生成用于远程通信的类 //文件的后缀 ...

  8. oracle锁表和解锁

    1.查看锁表清空 select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID; alter system k ...

  9. Vue_子级组件调用主组件函数

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. kernel: possible SYN flooding on port 80. Sending cookies

    1. sysctl -w net.ipv4.tcp_syncookies=1 #启用使用syncookiessysctl -w net.ipv4.tcp_synack_retries=1 #降低syn ...