#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
const int NN=1002;
const double inf=1000000000;
const double eps=1e-5;
typedef struct point{
double x,y,h;
}point;
int n;
point p[NN];
double l,r,mid;
double dis[NN][NN];
void get_dis()
{
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
{
dis[i][j]=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
if (dis[i][j]<d1) d1=dis[i][j];
}
}
double lowcost[NN];
bool intree[NN];
bool prim()
{
double sum=0.0;
int cur=1;
lowcost[cur]=0;
intree[cur]=true;
for (int i=2; i<=n; i++) { lowcost[i]=inf; intree[i]=false; }
for (int t=1; t<n; t++)
{
double min_cost=inf;
int k;
for (int i=1; i<=n; i++)
{
if (!intree[i])
{
if (lowcost[i]>fabs(p[cur].h-p[i].h)-mid*dis[cur][i])
lowcost[i]=fabs(p[cur].h-p[i].h)-mid*dis[cur][i];
if (lowcost[i]<min_cost) min_cost=lowcost[k=i];
}
}
sum+=min_cost;
intree[k]=true;
cur=k;
}
if (sum<=eps) return true;
else return false;
}
void solve()
{
get_dis();
l=0.0; r=1000.0;
while (r-l>eps)
{
mid=(l+r)*0.5;
if (prim()) r=mid;
else l=mid;
}
printf("%.3f\n",mid); //我会告诉你因为自作多情在这儿加了ep而WA了好几次么?不懂精度就不要乱搞。。。。。。
}
int main()
{
while (scanf("%d",&n),n)
{
for (int i=1; i<=n; i++) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].h);
solve();
}
return 0;
}
POJ2728最优比率生成树
最新推荐文章于 2021-05-09 20:10:49 发布