【圆(和球)的最小覆盖】【三分套三分(套三分)】
球的最小覆盖(三分套三分套三分)
1 /* 2 三分求球的最小覆盖 3 */ 4 #include<iostream> 5 #include<cstdio> 6 #include<cstring> 7 #include<algorithm> 8 #include<cmath> 9 using namespace std; 10 typedef long long ll; 11 const ll mod=9999973; 12 const double eps=1e-3; 13 int n; 14 double x[105],y[105],z[105]; 15 double dis3(double a,double b,double c){ 16 double ans=0; 17 for(int i=1;i<=n;i++){ 18 ans=max(ans,(x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b)+(z[i]-c)*(z[i]-c)); 19 } 20 return ans; 21 } 22 double dis2(double a,double b){ 23 double l=-100000; 24 double r=100000; 25 double ans=0; 26 while(r-l>=eps){ 27 double rmid=(r+l)/2; 28 double lmid=(l+rmid)/2; 29 if(dis3(a,b,lmid)<dis3(a,b,rmid)){ 30 r=rmid; 31 } 32 else l=lmid; 33 } 34 return dis3(a,b,l); 35 } 36 double dis(double a){ 37 double l=-100000; 38 double r=100000; 39 while(r-l>=eps){ 40 double rmid=(r+l)/2; 41 double lmid=(l+rmid)/2; 42 if(dis2(a,lmid)<dis2(a,rmid)){ 43 r=rmid; 44 } 45 else l=lmid; 46 } 47 return dis2(a,l); 48 } 49 int main(){ 50 // int n; 51 scanf("%d",&n); 52 for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&x[i],&y[i],&z[i]); 53 double l=-100000; 54 double r=100000; 55 while(r-l>=eps){ 56 double rmid=(r+l)/2; 57 double lmid=(l+rmid)/2; 58 if(dis(lmid)<dis(rmid)){ 59 r=rmid; 60 } 61 else l=lmid; 62 } 63 printf("%.6lf\n",sqrt(dis(l))); 64 return 0; 65 }
同理可得圆的最小覆盖(三分套三分)