码迷,mamicode.com
首页 > 其他好文 > 详细

Country Meow

时间:2018-11-22 22:33:40      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:分享图片   double   col   sed   tor   hid   vector   http   \n   

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 }
View Code

 

Country Meow

标签:分享图片   double   col   sed   tor   hid   vector   http   \n   

原文地址:https://www.cnblogs.com/Fighting-sh/p/10004196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!