poj 2069

时间:2021-04-27 14:31:38

唔。

这道题的火候比较巧妙。

我们是每次找到一个最远的点,然后向那个最远点逼近。

这显然非常合理。

 #include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm> using namespace std;
typedef double db;
const db eps = 1e-;
const db delta = 0.98;
const db INF = 1e100;
db random(){
return (rand()&?:-)*rand()*1.0/;
}
struct P3{
db x,y,z;
P3 operator + (P3 k1){return (P3){x+k1.x,y+k1.y,z+k1.z};}
P3 operator - (P3 k1){return (P3){x-k1.x,y-k1.y,z-k1.z};}
P3 operator / (db k1){ return (P3){x/k1,y/k1,z/k1};}
P3 operator * (db k1){ return (P3){x*k1,y*k1,z*k1};}
db abs(){return sqrt(x*x+y*y+z*z);}
};
P3 p[];
int n;
db F(P3 x){
db res=;
for(int i=;i<n;i++){
res=max(res,(x-p[i]).abs());
}
return res;
}
db SA(){
db t = ;
db ans = INF;
P3 x = {,,};
while (t>eps){
db mx = ;int id=-;
for(int i=;i<n;i++){
if((x-p[i]).abs()>mx){
mx=(x-p[i]).abs();
id=i;
}
}
ans = min(ans,mx);
ans=mx;
x=x+(p[id]-x)/mx*t;
t*=delta;
}
printf("%.5f\n",ans);
}
int main(){
while (scanf("%d",&n)&&n){
for(int i=;i<n;i++){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
SA();
}
}