//最小覆盖球
#include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #define N 150 #define eps 1e-8 #define T 100 #define delta 0.98 #define INF 1e99 using namespace std; struct Point { double x, y, z; }; Point p[N]; double dist(Point A, Point B) { 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)); } double Search(Point p[], int n) { Point s; s.x=s.y=s.z=0; double t = 10000; double ans = INF; while(t > eps) { int k = 0; for(int i = 0; i < n; i++) if(dist(s, p[i]) > dist(s, p[k])) k = i; double d = dist(s, p[k]); ans = min(ans, d); s.x += (p[k].x - s.x) / d * t; s.y += (p[k].y - s.y) / d * t; s.z += (p[k].z - s.z) / d * t; t *= delta; } return ans; } int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i = 0; i < n; i++) cin >> p[i].x >> p[i].y >> p[i].z; double ans = Search(p, n); printf("%.7lf ", ans); } return 0; }
//最小覆盖圆 #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #define N 1000 #define eps 1e-8 #define delta 0.98 #define INF 1e99 using namespace std; struct Point { double x, y, z; }; Point p[N]; double dist(Point A, Point B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)); } double Search(Point p[], int n) { Point s; s.x=s.y=s.z=0; double t = 1000; double ans = INF; while(t > eps) { int k = 0; for(int i = 0; i < n; i++) if(dist(s, p[i]) > dist(s, p[k])) k = i; double d = dist(s, p[k]); ans = min(ans, d); s.x += (p[k].x - s.x) / d * t; s.y += (p[k].y - s.y) / d * t; // s.z += (p[k].z - s.z) / d * t; t *= delta; } printf("%.2f %.2f %.2f ",s.x,s.y,ans); } int main() { int n; while(scanf("%d",&n)&&n!=0) { for(int i = 0; i < n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); double ans = Search(p, n); } return 0; }