#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#pragma warning(disable:4996)
const double EPS = 1e-15;
const double rate = 0.9995;
#define INF 2000000000
#define PI acos(-1.0)
const int N = 30;
const int M = 30;
using namespace std;
class Point
{
public:
double x, y, z;
};
double dist(const Point &p1, const Point &p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) + (p1.z - p2.z)*(p1.z - p2.z));
}
double getMaxDist(const Point&p, const vector<Point>&point)
{
double ans = 0.0;
for (size_t i = 0; i != point.size(); i++)
{
ans = max(ans, dist(p, point[i]));
}
return ans;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
srand((unsigned)time(NULL));
int n;
while (cin >> n&&n)
{
vector<Point>point(n);
double max_x = -2000000000.0, max_y = -2000000000.0, max_z = -2000000000.0;
double min_x = 2000000000.0, min_y = 2000000000.0, min_z = 2000000000.0;
for (int i = 0; i < n; i++)
{
cin >> point[i].x >> point[i].y >> point[i].z;
max_x = max(max_x, point[i].x);
max_y = max(max_y, point[i].y);
max_z = max(max_z, point[i].z);
min_x = min(min_x, point[i].x);
min_y = min(min_y, point[i].y);
min_z = min(min_z, point[i].z);
}
Point curpoint;
curpoint.x = (max_x - min_x) / 2.0;
curpoint.y = (max_y - min_y) / 2.0;
curpoint.z = (max_z - min_z) / 2.0;
double delta = 100;
double ans = getMaxDist(curpoint, point);
while (delta > 1e-15)
{
double theta1 = (double)(rand() % 1000) / 1000.0*2.0*PI;
double theta2 = (double)(rand() % 1000) / 1000.0*2.0*PI;
Point nextpoint;
nextpoint.x = curpoint.x + cos(theta1)*cos(theta2)*delta;
nextpoint.y = curpoint.y + cos(theta1)*sin(theta2)*delta;
nextpoint.z = curpoint.z + sin(theta1)*delta;
double distance = getMaxDist(nextpoint, point);
if (distance < ans)
{
curpoint = nextpoint;
ans = distance;
}
delta *= rate;
}
printf("%.5lf\n", ans);
}
return 0;
}
poj_2069_Super Star_WA
最新推荐文章于 2020-04-18 11:37:19 发布