Country Meow
和这基本一样 https://www.cnblogs.com/Fighting-sh/p/9809518.html
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<string> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 using namespace std; 11 12 struct Point{ 13 double x,y,z; 14 }p[105]; 15 16 double dist(Point a,Point b){ 17 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)); 18 } 19 20 double ac(int n){ 21 double ans=1e9; 22 Point tmp; 23 tmp.x=tmp.y=tmp.z=0;; 24 int s=1; 25 double step=1000; 26 double esp=0.0000001; 27 while(step>esp){ 28 for(int i=1;i<=n;i++){ 29 if(dist(tmp,p[s])<dist(tmp,p[i])) s=i; 30 } 31 double Dist=dist(tmp,p[s]); 32 ans=min(ans,Dist); 33 tmp.x+=(p[s].x-tmp.x)/Dist*step; 34 tmp.y+=(p[s].y-tmp.y)/Dist*step; 35 tmp.z+=(p[s].z-tmp.z)/Dist*step; 36 step*=0.999; 37 } 38 return ans; 39 } 40 41 int main(){ 42 int n; 43 while(~scanf("%d",&n)){ 44 if(!n) break; 45 for(int i=1;i<=n;i++){ 46 scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].z); 47 } 48 double ans=ac(n); 49 printf("%.5f\n",ans); 50 } 51 }
原文地址:https://www.cnblogs.com/Fighting-sh/p/10004196.html
时间: 2024-10-11 16:07:33