1.emm,最小球覆盖的裸题,直接模拟退火。。
#include<bits/stdc++.h>
using namespace std;
#pragma warning(disable:4996)
const double eps = 1e-8;
struct point3D
{
double x, y, z;
} p[105];
int n;
double dis(point3D a, point3D 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 solve()
{
double step = 10000, ans = 1e30, mt;
point3D z;
z.x = z.y = z.z = 0;
int s = 0;
while (step > eps)
{
for (int i = 0; i < n; i++)
if (dis(z, p[s]) < dis(z, p[i]))
s = i;
mt = dis(z, p[s]);
ans = min(ans, mt);
z.x += (p[s].x - z.x) / mt * step;
z.y += (p[s].y - z.y) / mt * step;
z.z += (p[s].z - z.z) / mt * step;
step *= 0.98;
}
return ans;
}
int main()
{
double ans;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
scanf("%lf%lf%lf", &p[i].x, &p[i].y, &p[i].z);
ans = solve();
printf("%.7f\n", ans);
}
return 0;
}