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 ...
随机推荐
- Struts2自己定义拦截器实例—登陆权限验证
版本号:struts2.1.6 此实例实现功能:用户须要指定username登陆,登陆成功进入对应页面运行操作,否则返回到登陆页面进行登陆,当直接訪问操作页面(登陆后才干訪问的页面)时则不同意,须返回 ...
- PHP安全编程:主机文件目录浏览(转)
除了能在共享服务器上读取任意文件之外,攻击者还能建立一个可以浏览文件系统的脚本.由于你的大多数敏感文件不会保存在网站主目录下,此类脚本一般用于找到你的源文件的所在位置.请看下例: 01 <?ph ...
- [转] C++临时变量的生命周期
http://www.cnblogs.com/catch/p/3251937.html C++中的临时变量指的是那些由编译器根据需要在栈上产生的,没有名字的变量. 主要的用途主要有两类: 1) 函数的 ...
- oracle的sql优化
http://www.cnblogs.com/rootq/archive/2008/11/17/1334727.html
- js实现图片上传及预览---------------------->>兼容ie6-8 火狐以及谷歌
<head runat="server"> <title>图片上传及预览(兼容ie6/7/8 firefox/chrome)</title> & ...
- javascript MD5加密
/* * Javascript MD5 library - version 0.4 * * Coded (2011) by Luigi Galli - LG@4e71.org - * http://f ...
- Activity之间的数据传递(Arraylist)
1.使用Serialiable方法 实现序列化 2.使用Parcelable方法(这是android自己封装的类) Parcel类是封装数据的容器,封装后的数据通过Intent和IPC传递 实 ...
- RoadTrip 学习笔记
#RoadTrip 学习笔记 本篇是在Cmd Markdown中写完粘贴来的. RoadTrip介绍 RoadTrip 项目地址:https://github.com/romainguy/road-t ...
- amCharts 破解
官网下载 http://www.amcharts.com 然后找到amcharts.js , 打开搜索关键字 “utm_source=swf&utm_medium=demo&utm_c ...
- 抓取锁的sql语句-第五次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHA ...