poj 2031Building a Space Station
http://poj.org/problem?id=2031
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
const int inf=<<;
#define maxn 110
using namespace std; struct point
{
double x,y,z;
double r;
}p[];
int n;
double g[maxn][maxn];
bool vis[maxn];
double dist[maxn],ans; double sqr(double a)
{
return a*a;
} inline double Sqrt(double a)
{
return a<=?:sqrt(a);
} double dis(point a,point b)
{
return (Sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)+sqr(a.z-b.z))-a.r-b.r);
} bool prim()
{
memset(vis,false,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]>g[k][j])
dist[j]=g[k][j];
}
}
return false;
} int main()
{
while(scanf("%d",&n)&&n){
memset(g,inf,sizeof(g));
for(int i=; i<n; i++)
{
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z,&p[i].r);
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(dis(p[i],p[j])<=)
{
g[i][j]=;
}
else g[i][j]=dis(p[i],p[j]);
}
}
prim();
printf("%.3lf\n",ans);
}
return ;
}
poj 2031Building a Space Station的更多相关文章
- poj 2031--Building a Space Station(prim)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6064 Accepte ...
- poj 2031Building a Space Station(几何判断+Kruskal最小生成树)
/* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...
- POJ Building a Space Station 最小生成树
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15664 Accepted: 6865 Description You ...
- poj Building a Space Station
http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...
- poj 2031 Building a Space Station【最小生成树prime】【模板题】
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5699 Accepte ...
- (最小生成树) Building a Space Station -- POJ -- 2031
链接: http://poj.org/problem?id=2031 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6011 ...
- 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 ...
- Building a Space Station POJ 2031 【最小生成树 prim】
http://poj.org/problem?id=2031 Description You are a member of the space station engineering team, a ...
随机推荐
- Android网络框架---OkHttp3
1.添加依赖 compile 'com.squareup.okhttp3:okhttp:3.4.2' project Structure-->dependencied/搜索okhttp. com ...
- 黑白图像(DFS)
输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图6-11所示的图形有3个八连块. 图6-11 拥有3 ...
- JAVA IDE基本操作常识
快捷键: Ctrl+/ 选中区单行注释和 取消 选中区单行注释和 Alt + / 代码辅助 shift + Ctrl +/ 选中区多行注释 shift + Ctrl +\ 取消选中区多行注释 Ct ...
- noip 2010 关押罪犯 (二分图染色 并茶几)
/* 二分图染色版本 两个监狱对应二部图的两部分 在给定的怨气值里二分 对于每一个Ci 进行染色判断是否合法 染色的时候 如果这条边的ci > Ci 这两个人就带分开 即染成不同的颜色 如果染色 ...
- 从今天开始学习C#啦
此博客为证,在下从今天开始学习C#,并把心得体会记录下来.
- Linq101-CustomSequence
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class CustomS ...
- Web字体库下载及转换工具
1.字体现在网站: http://ztxz.org/ 2.Web字体在线格式转换器: http://www.freefontconverter.com/ 3.
- class-loader.
the jdk hierarchical relationship of class-loader ----Module Class Loading and Bootstrapping---- boo ...
- protocol buffer VS 2013编译出错
protocol buffer 在VS2013编译会出现以下错误. 解决办法 把宏加上, 问题解决. 注: 该错误只出现在Debug版本.
- JVM内存管理及垃圾回收
一.JVM内存的构 Java虚拟机会将内存分为几个不同的管理区,这些区域各自有各自的用途,根据不同的特点,承担不同的任务以及在垃圾回收时运用不同的算法.总体分为下面几个部分: 程序计数器(Progra ...