| | #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; |
| | } |
| | |
| | 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}); |
| | } |
| | } |
| | } |
| | |
| | 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); |
| | |
| | if (dsq >= 4 * R * R) { |
| | continue; |
| | } |
| | |
| | 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; |
| | } |
| | } |
| | } |
| | |
| | |
| | |
| | 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; |
| | } |
| |
|