裸的最小球覆盖。
坐标范围大一些所以我们把初始的温度也设置的大一些。
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef double db; 5 const db INF = 1e100; 6 const db delta = 0.98; 7 const db eps = 1e-8; 8 struct p3{ 9 db x,y,z; 10 p3 operator +(const p3&k1)const { return p3{x+k1.x,y+k1.y,z+k1.z};} 11 p3 operator -(const p3&k1)const { return p3{x-k1.x,y-k1.y,z-k1.z};} 12 p3 operator *(const db k1)const { return p3{x*k1,y*k1,z*k1};} 13 p3 operator /(const db k1)const { return p3{x/k1,y/k1,z/k1};} 14 db abs(){ return sqrt(x*x+y*y+z*z);} 15 db dis(p3 k1){ return (*this-k1).abs();} 16 }; 17 int n; 18 p3 p[105]; 19 int main(){ 20 scanf("%d",&n); 21 for(int i=1;i<=n;i++){ 22 scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z); 23 } 24 db T = 100000; 25 db ans = INF; 26 p3 x = {0,0,0}; 27 while (T>eps){ 28 db mx =0;int id=-1; 29 for(int i=1;i<=n;i++){ 30 if((p[i]-x).abs()>mx){ 31 mx=(p[i]-x).abs(); 32 id=i; 33 } 34 } 35 ans = min(ans,mx); 36 x=x+(p[id]-x)/mx*T; 37 T*=delta; 38 } 39 printf("%.11f ",ans); 40 }