Problem p02805 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int x[55], y[55];
double distance(int I, int J) {
  return sqrt((x[I] - x[J]) * (x[I] - x[J]) + (y[I] - y[J]) * (y[I] - y[J]));
}

int main() {
  int n;
  cin >> n;
  double ans = 1e9;
  double tmp;
  double a, b, c;
  double A, B, C;
  queue<pair<double, double>> q;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      else {
        for (int k = 0; k < n; k++) {
          if (i == k || j == k)
            q.push(make_pair((x[i] + x[j]) / 2.0, (y[i] + y[j]) / 2.0));
          else {
            a = distance(i, j);
            b = distance(k, j);
            c = distance(i, k);
            if (a + b > c && a + c > b && b + c > a) {
              A = sin(2.0 * acos((b * b + c * c - a * a) / (2.0 * b * c)));
              B = sin(2.0 * acos((a * a + c * c - b * b) / (2.0 * a * c)));
              C = sin(2.0 * acos((a * a + b * b - c * c) / (2.0 * a * b)));
              q.push(make_pair((A * x[k] + B * x[i] + C * x[j]) / (A + B + C),
                               (A * y[k] + B * y[i] + C * y[j]) / (A + B + C)));
            }
          }
        }
      }
    }
  }
  while (!q.empty()) {
    tmp = 0;
    for (int i = 0; i < n; i++)
      tmp =
          max(tmp, sqrt((x[i] - q.front().first) * (x[i] - q.front().first) +
                        (y[i] - q.front().second) * (y[i] - q.front().second)));
    ans = min(tmp, ans);
  }
  cout << fixed << setprecision(16);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int x[55], y[55];
double distance(int I, int J) {
  return sqrt((x[I] - x[J]) * (x[I] - x[J]) + (y[I] - y[J]) * (y[I] - y[J]));
}

int main() {
  int n;
  cin >> n;
  double ans = 1e9;
  double tmp;
  double a, b, c;
  double A, B, C;
  queue<pair<double, double>> q;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      else {
        for (int k = 0; k < n; k++) {
          if (i == k || j == k)
            q.push(make_pair((x[i] + x[j]) / 2.0, (y[i] + y[j]) / 2.0));
          else {
            a = distance(i, j);
            b = distance(k, j);
            c = distance(i, k);
            if (a + b > c && a + c > b && b + c > a) {
              A = sin(2.0 * acos((b * b + c * c - a * a) / (2.0 * b * c)));
              B = sin(2.0 * acos((a * a + c * c - b * b) / (2.0 * a * c)));
              C = sin(2.0 * acos((a * a + b * b - c * c) / (2.0 * a * b)));
              q.push(make_pair((A * x[k] + B * x[i] + C * x[j]) / (A + B + C),
                               (A * y[k] + B * y[i] + C * y[j]) / (A + B + C)));
            }
          }
        }
      }
    }
  }
  while (!q.empty()) {
    tmp = 0;
    for (int i = 0; i < n; i++)
      tmp =
          max(tmp, sqrt((x[i] - q.front().first) * (x[i] - q.front().first) +
                        (y[i] - q.front().second) * (y[i] - q.front().second)));
    ans = min(tmp, ans);
    q.pop();
  }
  cout << fixed << setprecision(16);
  cout << ans << endl;
}