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的更多相关文章

  1. poj 2031--Building a Space Station(prim)

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

  2. poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

    /* 最小生成树 + 几何判断 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的!此时的距离按照0计算 */ #include<iostream> #incl ...

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

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

  4. poj Building a Space Station

    http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...

  5. poj 2031 Building a Space Station【最小生成树prime】【模板题】

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

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

    链接: http://poj.org/problem?id=2031 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6011 ...

  7. POJ 2031 Building a Space Station【经典最小生成树】

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

  8. Building a Space Station POJ - 2031

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

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

随机推荐

  1. [Unity-24] Unity的四种载入场景的方法

    Unity官方提供了4种载入场景(scene)的方法.各自是: 1. Application.LoadLevel():同步载入 2. Application.LoadLevelAsync():异步载入 ...

  2. 我的搜索优化记录(一):中文分词优化IK Analyzer

    搜索绝对不仅仅是搭起框架,跑出结果就完成的工作,之后分词.排序等等的优化才是重头戏. 先交代下背景:这个搜索是我一个人负责搭建并优化的项目,主要索引对象为歌曲.歌手MV等等. 使用技术:Lucene. ...

  3. [Javascript] String method: endsWith() && startsWith()

    With endsWith && startsWith, you can easily find out whether the string ends or starts with ...

  4. [转] C++11带来的move语义

    PS: 通过引入接收右值的函数形参,可以通过接收右值来实现高效 PS在C++11中,标准库在<utility>中提供了一个有用的函数std::move,这个函数的名字具有迷惑性,因为实际上 ...

  5. 从页面底部向上弹出dialog,消失时逐渐向下(转)

    我想实现一个效果,从底部向上逐渐弹出.如下图所示: 1.点击 显示 按钮时,一个dialog对话框从底部慢慢向上弹出. 2.关闭dialog时, dialog缓慢的移动向底部消失.很平滑的效果.   ...

  6. Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历

    1. Collection的迭代器: Iterator iterator():迭代器,集合的专用遍历方式 2. 代码示例: package cn.itcast_03; import java.util ...

  7. 成为VR开发者的六个基本问题

    2016-05-31 小小CTO 未来CTO 我常被问起能否提供更多的建议,帮助其他人进入这个行业,或是做VR开发人员该怎么赚钱.我很难具体回答,因为每个人的情况都很不一样.不过还是有一些建议适用于想 ...

  8. jQuery的矿建结构小demo举例

    (function (global) { var document = global.document,//变成局部变量提高搜索的性能 init;// 核心函数 function itcast(sel ...

  9. jquery Tab默认情况下自动切换

    <!DOCTYPE html><html lang="zh-CN"><head><meta http-equiv="Conten ...

  10. Apache下Worker模式MPM参数分析

    我的worker.c配置如下:<IfModule mpm_worker_module> ServerLimit   32 ThreadLimit   128 StartServers   ...