#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1010
#define eps 1e-6
#define INF 0x3f3f3f3f
using namespace std;
int n;
double top,bot;
struct point
{
double x,y,z;
}pt[N];
struct line
{
int x,y;
double get,cost,l;
}l[N*N];
int cmp(line a,line b)
{
return a.l>b.l;
}
double thedis[N];
int theclo[N];
double function[N][N];
double get[N][N];
double cost[N][N];
double prim(int u)
{
double ret=0;
for(int i=1;i<=n;i++)
{
if(i==u)thedis[i]=-1,theclo[i]=-1;
else thedis[i]=function[u][i],theclo[i]=u;
}
for(int i=1;i<n;i++)
{
double val=-10000000;
int no;
for(int j=1;j<=n;j++)
{
if(theclo[j]!=-1&&thedis[j]>val)val=thedis[j],no=j;
}
ret+=thedis[no];
top+=get[theclo[no]][no];
bot+=cost[theclo[no]][no];
theclo[no]=-1;
for(int j=1;j<=n;j++)
{
if(theclo[j]!=-1&&function[no][j]>thedis[j])thedis[j]=function[no][j],theclo[j]=no;
}
}
return ret;
}
int main()
{
while(~scanf("%d",&n))
{
if(n==0)break;
for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&pt[i].x,&pt[i].y,&pt[i].z);
int linetot=0;
double l=0,r=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)continue;
cost[i][j]=fabs(pt[i].z-pt[j].z);
get[i][j]=sqrt((pt[i].x-pt[j].x)*(pt[i].x-pt[j].x)+(pt[i].y-pt[j].y)*(pt[i].y-pt[j].y));
r=max(r,get[i][j]/cost[i][j]);
}
}
double ans=0;
while(r-l>eps)
{
double mid=(l+r)/2.0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j)continue;
function[i][j]=get[i][j]-mid*cost[i][j];
}
}
top=0,bot=0;
double ret=prim(1);
if(ret-eps>=0)ans=max(ans,top/bot),l=mid+eps;
else r=mid-eps;
}
printf("%.3lf\n",1.0/ans);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wzq_qwq/article/details/47724087