Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Why wa? I've been trying on tihs for several days...

Posted by szwj at 2008-03-05 16:07:35 on Problem 2069 and last updated at 2008-03-05 16:09:10
```#include <stdio.h>
#include <math.h>

double pl[30][3];
double formula[3][4];

inline double dim2(int a,int b)
{
double x=(pl[a][0]+pl[b][0])/2,y=(pl[a][1]+pl[b][1])/2,z=(pl[a][2]+pl[b][2])/2;
double ret=(x-pl[a][0])*(x-pl[a][0])+(y-pl[a][1])*(y-pl[a][1])+(z-pl[a][2])*(z-pl[a][2]);
if(fabs(ret)<1e-7)
return -1;
else
return ret;
}

inline double fdet3(int a,int b,int c)
{
return formula[0][a]*formula[1][b]*formula[2][c]
+formula[0][b]*formula[1][c]*formula[2][a]
+formula[0][c]*formula[1][a]*formula[2][b]
-formula[0][c]*formula[1][b]*formula[2][a]
-formula[0][a]*formula[1][c]*formula[2][b]
-formula[0][b]*formula[1][a]*formula[2][c];
}

inline bool solve3(double &x,double &y,double &z)
{
double comm=fdet3(0,1,2);
if(fabs(comm)<1e-7)
return false;
x=fdet3(3,1,2)/comm;
y=fdet3(0,3,2)/comm;
z=fdet3(0,1,3)/comm;
return true;
}

inline double dim3(int a,int b,int c)
{
int i;
formula[0][3]=0; formula[1][3]=0; formula[2][3]=0;
for(i=0;i<3;i++)
{
formula[0][i]=pl[a][i]-pl[b][i];
formula[1][i]=pl[a][i]-pl[c][i];
formula[0][3]+=formula[0][i]*(pl[a][i]+pl[b][i])/2;
formula[1][3]+=formula[1][i]*(pl[a][i]+pl[c][i])/2;
}
double sl=0.0;
formula[2][0]=formula[0][1]*formula[1][2]-formula[0][2]*formula[1][1];
formula[2][1]=-formula[0][0]*formula[1][2]+formula[0][2]*formula[1][0];
formula[2][2]=formula[0][0]*formula[1][1]-formula[0][1]*formula[1][0];
if(fabs(formula[2][0])<1e-7 && fabs(formula[2][1])<1e-7 && fabs(formula[2][2])<1e-7)
return -1;
for(i=0;i<3;i++)
formula[2][3]+=formula[2][i]*pl[a][i];
double x,y,z;
if(solve3(x,y,z))
return (x-pl[a][0])*(x-pl[a][0])+(y-pl[a][1])*(y-pl[a][1])+(z-pl[a][2])*(z-pl[a][2]);
else
return -1;
}

inline double dim4(int a,int b,int c,int d)
{
int i;
formula[0][3]=0; formula[1][3]=0; formula[2][3]=0;
for(i=0;i<3;i++)
{
formula[0][i]=pl[a][i]-pl[b][i];
formula[1][i]=pl[a][i]-pl[c][i];
formula[2][i]=pl[a][i]-pl[d][i];
formula[0][3]+=formula[0][i]*(pl[a][i]+pl[b][i])/2;
formula[1][3]+=formula[1][i]*(pl[a][i]+pl[c][i])/2;
formula[2][3]+=formula[2][i]*(pl[a][i]+pl[d][i])/2;
}
double x,y,z;
if(solve3(x,y,z))
return (x-pl[a][0])*(x-pl[a][0])+(y-pl[a][1])*(y-pl[a][1])+(z-pl[a][2])*(z-pl[a][2]);
else
return -1;
}

int main()
{
int n;
while(scanf("%d",&n),n)
{
int i,j,k,l;
double max=-1,temp;
for(i=0;i<n;i++)
for(j=0;j<3;j++)
scanf("%lf",&pl[i][j]);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
temp=dim2(i,j);
if(temp>max)
max=temp;
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
for(k=j+1;k<n;k++)
{
temp=dim3(i,j,k);
if(temp>max)
max=temp;
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
for(k=j+1;k<n;k++)
for(l=k+1;l<n;l++)
{
temp=dim4(i,j,k,l);
if(temp>max)
max=temp;
}
printf("%0.5lf\n",sqrt(max)+1e-7);
}
return 0;
}```

Followed by: