fork(38) download
  1. #include <cstdio>
  2. #include <cmath>
  3. int n;
  4. double x[1005], y[1005], X, Y, d, e;
  5. double dist(double a, double b) {
  6. return a*a + b*b;
  7. }
  8. int main() {
  9. scanf("%d", &n);
  10. for (int i = 0; i < n; i++) {
  11. scanf("%lf%lf", &x[i], &y[i]);
  12. X += x[i]; Y += y[i];
  13. }
  14. X /= n; Y /= n;
  15. double P = 0.1;
  16. for (int i = 0; i < 30000; i++) {
  17. int f = 0;
  18. d = dist(X - x[0], Y - y[0]);
  19. for (int j = 1; j < n; j++) {
  20. e = dist(X - x[j], Y - y[j]);
  21. if (d < e) { d = e; f = j; }
  22. }
  23. X += (x[f] - X)*P;
  24. Y += (y[f] - Y)*P;
  25. P *= 0.999;
  26. }
  27. printf("%.3lf %.3lf\n%.3lf", X, Y, sqrt(d));
  28. }
Success #stdin #stdout 0s 3316KB
stdin
5
5 -2
-3 -2
-2 5
1 6
0 2
stdout
1.000 1.000
5.000