Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,556 Bytes
f7ba5f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

const int SAMPLES = 500;
const int BOUNDS = 50;

int N;
vector<pair<double, double>> P;

inline double distsq(double dx, double dy) { return dx * dx + dy * dy; }

bool check(int x, int y, int r) {
  double Rsq = r*r;
  for (int i = 0; i < min(N, SAMPLES); i++) {
    if (distsq(x - P[i].first, y - P[i].second) > Rsq) {
      return false;
    }
  }
  return true;
}

void solve() {
  cin >> N;
  P.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i].first >> P[i].second;
  }
  // Generate valid circles.
  vector<tuple<int, int, int>> circles;
  for (int Ax = 0; Ax <= BOUNDS; Ax++) {
    for (int Ay = 0; Ay <= BOUNDS; Ay++) {
      int Ar = 1;
      while (Ar <= BOUNDS && !check(Ax, Ay, Ar)) {
        Ar++;
      }
      if (Ar <= BOUNDS) {
        circles.push_back({Ax, Ay, Ar});
      }
    }
  }
  // Try for all valid circles.
  int bestAx = -1, bestAy = -1, bestBx = -1, bestBy = -1, bestR = -1;
  double bestArea = 999999;
  for (int a = 0; a < (int)circles.size(); a++) {
    auto [Ax, Ay, R] = circles[a];
    for (int b = a + 1; b < (int)circles.size(); b++) {
      auto [Bx, By, Br] = circles[b];
      if (R != Br) {
        continue;
      }
      double dsq = distsq(Ax - Bx, Ay - By);
      // Fail if circles don't overlap.
      if (dsq >= 4 * R * R) {
        continue;
      }
      // Choose the answer that minimizes the area of the overlap.
      double d = sqrt(dsq);
      double fouradsq = sqrt((4 * R * R) - dsq);
      double area = R * R * M_PI;
      area -= 2 * R * R * atan2(d, fouradsq);
      area -= 0.5 * d * fouradsq;
      if (area < bestArea) {
        bestArea = area;
        bestAx = Ax;
        bestAy = Ay;
        bestBx = Bx;
        bestBy = By;
        bestR = R;
      }
    }
  }
  // Compute sum of squared distance to points from both A and B.
  // If B's sum is less, B is actually A.
  // Note: We can afford to use all N points for this, no need to sample.
  double Asum = 0, Bsum = 0;
  for (auto [x, y] : P) {
    Asum += distsq(x - bestAx, y - bestAy);
    Bsum += distsq(x - bestBx, y - bestBy);
  }
  if (Bsum < Asum) {
    swap(bestAx, bestBx);
    swap(bestAy, bestBy);
  }
  cout << bestAx << " " << bestAy << " " << bestBx << " " << bestBy << " "
       << bestR << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}