首页 > 其他 > 详细

最小球覆盖板子

时间:2020-08-10 21:36:20      阅读:92      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <math.h>
 4 using namespace std;
 5 const int MAXN=105;
 6 const double EPS=1e-8;
 7 struct Point{
 8     double x,y,z;
 9     Point(double _x=0,double _y=0,double _z=0){
10         x=_x;y=_y;z=_z;
11     }
12 };
13 Point Dots[MAXN];
14 int n;
15  
16 double Distance(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 double Solve(){
20     double Step=100000,ans=1e9,mt;
21     Point z=Point(0.0,0.0,0.0);
22     int s=0;
23     while(Step>EPS){
24         for(int i=1;i<=n;++i){
25             if(Distance(z,Dots[s])<Distance(z,Dots[i])){
26                 s=i;
27             }
28         }
29         mt=Distance(z,Dots[s]);
30         ans=min(ans,mt);
31         z.x+=(Dots[s].x-z.x)/mt*Step;
32         z.y+=(Dots[s].y-z.y)/mt*Step;
33         z.z+=(Dots[s].z-z.z)/mt*Step;
34         Step*=0.98;
35     }return ans;
36 }
37 int main(){
38 
39         scanf("%d",&n);
40         
41         for(int i=1;i<=n;++i){
42             double x,y,z;scanf("%lf%lf%lf",&x,&y,&z);
43             Dots[i]=Point(x,y,z);
44         }
45         printf("%.15f",Solve());
46     
47 }

 

最小球覆盖板子

原文:https://www.cnblogs.com/zpj61/p/13471981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!