poj Building a Space Station
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的更多相关文章
- POJ Building a Space Station 最小生成树
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15664 Accepted: 6865 Description You ...
- poj 2031 Building a Space Station【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
- POJ 2031 Building a Space Station【经典最小生成树】
链接: http://poj.org/problem?id=2031 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- Building a Space Station POJ - 2031
Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...
- POJ 2031 Building a Space Station
3维空间中的最小生成树....好久没碰关于图的东西了..... Building a Space Station Time Limit: 1000MS Memory Li ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5173 Accepte ...
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...
- 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 ...
- poj 2931 Building a Space Station <克鲁斯卡尔>
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5869 Accepted: 2 ...
随机推荐
- redis linux 基本命令
找到一个哥们 写的都是一步步打基础的学习东西 不光是知识也是学习方式 都值得学习.. reids 传送们-->> http://xuelianbobo.iteye.com/category ...
- DataGridView绑定BindingList<T>带数据排序的类
本文章转载:http://yuyingying1986.blog.hexun.com/30905610_d.html DataGridView绑定List<T>类时候,不会自动的进行排序. ...
- evernote出现“Sync failed due to unexpected problem at server side”的问题
继上次的"Invalid username and/or password"问题之后,evernote又出现了“Sync failed due to unexpected prob ...
- Eclipse连接SVN服务器
(1)安装 eclipse SVN 插件 插件名称 site-1.4.8.zip Help --> SoftwareUpdates --->Find and Insta ...
- [PWA] 5. Hijacking one type of request
Previously we saw how to Hijacking all the reqest, but this is not useful. So now we want to see how ...
- Maven Build Life Cycle--reference
What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the ord ...
- [转] doxygen使用总结
doxygen [功能] 为许多种语言编写的程序生成文档的工具. [举例] *生成一个模板配置文件,模板文件中有详细的注释: $doxgen -g test 这样,会生成一个test文件,1500多行 ...
- linux的文本管道连接处理技巧
举例1: strace -f -e open cpp Hello.cpp -o /dev/null 2>&1 | grep -v ENOENT | awk '{print $3}' 1) ...
- Python之路,Day21 - 常用算法学习
Python之路,Day21 - 常用算法学习 本节内容 算法定义 时间复杂度 空间复杂度 常用算法实例 1.算法定义 算法(Algorithm)是指解题方案的准确而完整的描述,是一系列解决问题的 ...
- 洛谷 1373 小a和uim之大逃离
/* 很容易想到f[i][j][k][l][01] 表示到ij点 两个人得分为kl 01表示这一步谁走的 因为起点不同 路径不同 所以要枚举起点.. 时间复杂度 O(nmk*nmk) 空间复杂度 O( ...