-
Notifications
You must be signed in to change notification settings - Fork 0
/
2069.cpp
46 lines (43 loc) · 987 Bytes
/
2069.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <vector>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;
#define MAXN 38
#define EPS 1e-8
#define fromto(from,to,i) for(int i=(from);i<=(to);++i)
struct Point {
double x,y,z;
} P[MAXN],S;
double dist(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
double solve(int n)
{
S.x=S.y=S.z=0;
double delta=100,ans=1e8;
while(delta>=EPS) {
int maxi=1;
fromto(1,n,i) if(dist(S,P[maxi])<dist(S,P[i])) maxi=i;
double dis=dist(S,P[maxi]);
ans=min(ans,dis);
S.x+=(P[maxi].x-S.x)/dis*delta;
S.y+=(P[maxi].y-S.y)/dis*delta;
S.z+=(P[maxi].z-S.z)/dis*delta;
delta*=0.999;
}
return ans;
}
int main()
{
while(true) {
int n;
scanf("%d",&n);
if(n==0) break;
fromto(1,n,i) scanf("%lf%lf%lf",&P[i].x,&P[i].y,&P[i].z);
printf("%.5lf\n",solve(n));
}
return 0;
}