1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 5;
int n; double ans;
struct Coordinate { double x, y, z; } c[MAX_N], mn, mx;
double dist(Coordinate a, Coordinate 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 calculate(Coordinate r) { double far_dis = 0; for (int i = 0; i < n; ++i) { far_dis = max(far_dis, dist(r, c[i])); }
ans = min(ans, far_dis); return far_dis; }
void silumated_anneling() { Coordinate cur = { rand() % (int(2e5) + 1) - 1e5, rand() % (int(2e5) + 1) - 1e5, rand() % (int(2e5) + 1) - 1e5, };
for (double t = 1e6; t > 1e-6; t *= 0.99) { Coordinate nex = { cur.x + t * ((double)rand() / RAND_MAX * 2 - 1), cur.y + t * ((double)rand() / RAND_MAX * 2 - 1), cur.z + t * ((double)rand() / RAND_MAX * 2 - 1), }; double cur_dis = calculate(cur); double nex_dis = calculate(nex); double delta = nex_dis - cur_dis; if (exp(-delta / t) > (double)rand() / RAND_MAX) { cur = nex; } } }
int main() { scanf("%d", &n);
for (int i = 0; i < n; i++) { scanf("%lf%lf%lf", &c[i].x, &c[i].y, &c[i].z); }
srand(time(0)); ans = INT_MAX;
for (int i = 0; i < 100; ++i) { silumated_anneling(); }
printf("%.10f\n", ans);
return 0; }
|