http://poj.org/problem?id=2031

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const double eps=1e-;
const int inf=<<;
int cmp(double x)
{
if(fabs(x)<eps) return ;
if(x>) return ;
return -;
} const double pi=acos(-1.0);
inline double sqr(double x)
{
return x*x;
} inline double Sqrt(double a)
{
return a<=?:sqrt(a);
} struct point
{
double x,y,z,r;
point(){}
point(double a,double b,double c,double d):x(a),y(b),z(c),r(d){}
}; double dis(const point &a,const point &b)
{
return Sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z));
} double dist[];
double diss[][],ans;
bool vis[];
bool prime(int n)
{
memset(vis,,sizeof(vis));
for(int i=; i<=n; i++)
dist[i]=inf;
ans=;dist[]=;
for(int i=; i<=n; i++){
double temp=inf;
int k=;
for(int j=; j<=n; j++)
{
if(!vis[j]&&dist[j]<temp)
{
temp=dist[j];
k=j;
}
}
if(temp==inf) return false;
vis[k]=true;
ans+=temp;
for(int j=; j<=n; j++)
{
if(!vis[j]&&dist[j]>diss[k][j])
{
dist[j]=diss[k][j];
}
}
}
return true;
}
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
point a[];
memset(diss,,sizeof(diss));
for(int i=; i<=n; i++)
{
scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z,&a[i].r);
}
memset(diss,,sizeof(diss));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(dis(a[i],a[j])-a[i].r-a[j].r<=)
diss[i][j]=;
else if(dis(a[i],a[j])-a[i].r-a[j].r>eps)
diss[i][j]=dis(a[i],a[j])-a[i].r-a[j].r;
}
}
prime(n);
printf("%.3lf\n",ans);
}
return ;
}

poj Building a Space Station的更多相关文章

  1. POJ Building a Space Station 最小生成树

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15664   Accepted: 6865 Description You ...

  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【经典最小生成树】

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

  4. Building a Space Station POJ - 2031

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

  5. POJ 2031 Building a Space Station

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

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

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

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

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

  8. 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 ...

  9. poj 2931 Building a Space Station &lt;克鲁斯卡尔&gt;

    Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5869 Accepted: 2 ...

随机推荐

  1. centos下的mysql安装

    卸载mysql yum remove mysql mysql-server mysql-libs compat-mysql51 rm -rf /var/lib/mysql rm /etc/my.cnf ...

  2. makeKeyAndVisible的作用

    [self.window makeKeyAndVisible]; 这个是便捷方法,去使被使用对象的主窗口显示到屏幕的最前端.你也可以使用hiddenUIView方法隐藏这个窗口

  3. 阿基米德项目ALS矩阵分解算法应用案例

    转自:https://github.com/ceys/jdml/wiki/ALS 阿基米德项目ALS矩阵分解算法应用案例 编写人:ceys/youyis 最后更新时间:2014.5.12 一.算法描述 ...

  4. Android蓝牙操作笔记(转)

    蓝牙是一种支持设备短距离传输数据的无线技术.android在2.0以后提供了这方面的支持. 从查找蓝牙设备到能够相互通信要经过几个基本步骤(本机做为服务器): 1.设置权限 在manifest中配置 ...

  5. CentOS修改SSH默认端口

    1. 修改配置文件 vim /etc/ssh/sshd_config 修改 #Port 22 这行,  去掉 #  修改后面的端口号 例如 Port 2123 重启sshd服务 /etc/init.d ...

  6. HDU5319

    题意:给一个矩形染色,顺笔表示红色,逆笔表示蓝色(既一捺和一丿),交叉表示绿色,然后给你一个图,问你用多少笔能画出这个图来. 思路:对这个图直接模拟即可,如果点i,j坐标为红色,那么判断上一个路径点是 ...

  7. Photon的log使用

    添加log引用,设置log文件在Photon根目录下的log文件夹内. using ExitGames.Logging;using ExitGames.Logging.Log4Net; public ...

  8. 安装php时,make test报错

    Build complete. Don't forget to run 'make test'. [root@localhost php-5.4.5]# make test ERROR: Cannot ...

  9. 【转】那些好用的iOS开发工具

    原文:http://www.devtang.com/blog/2014/06/29/ios-dev-tools/ 前言 从苹果发明iPhone起,AppStore上的一个又一个类似flappy bir ...

  10. JavaScript--数组--关联(hash)数组

    关联(hash)数组的原理: hash算法: 接收一个字符串,计算出一个尽量不重复的序号 不同的字符串,计算出的序号尽量不同 相同的字符串,计算出的序号一定是相同 存入数据时: 将自定义下标名称交给h ...