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 ...
随机推荐
- jiaocheng https://github.com/CarpenterLee/JCFInternals
https://github.com/CarpenterLee/JCFInternals
- js判断字符串是否包含指定的字符
判断字符串是否包含指定字符是很常用的功能,比如说,注册时用户名限制不能输入"管理员",或者需要js判断url跳转链接是否包含某个关键词等-- <!DOCTYPE html&g ...
- [Flux] Component / Views
The application will dislay a some catalogs, and each catalog has title image, description. Catalog: ...
- 论C++与三国
Scott Meyers曾说过,C++语言是一个语言联邦.C++包含面向过程,面向对象,泛型编程编程思想.现在C++11有加了一堆新特性,语言联邦更为庞大. 程序员们.常常挑起语言之争,甚至连大师级人 ...
- linux下查看磁盘空间
如果要查看磁盘还剩多少空间,当然是用df的命令了. [root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda2 ...
- Swift: 基本操作符
这里只讲一下Swift中比较特殊的操作符,在其他语言中也存在操作符就不再讲了 Nil-Coalescing Operator: ?? The nil-coalescing operator (a ?? ...
- css之选择器
我们都用过jquery,使用jquery选择器,非常的简单,最近刚好有项目上手,拿起书本看了一下,发现好多的东西都忘掉了,好记性不如烂笔头,就将这章内容记录下来,现在我们看下css原生的选择器. 选择 ...
- 数据库内存泄漏——A SQLiteConnection object for database '/data/data/.../databases/....db' was leaked!
详细异常: A SQLiteConnection object for database '/data/data/.../database/....db' was leaked! Please ...
- 9.5noip模拟试题
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer.o ...
- Sublime Text插件之Emmet
转载:http://www.w3cplus.com/tools/using-emmet-speed-front-end-web-development.html Emmet插件以前被称作为Zen Co ...