Problem p00090 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<double, double> P;
#define eps 1e-7
#define fi first
#define sec second
int n, ans;
P circle[105];
double sq(double x) { return x * x; }
double culc_dist(int s, int t) {
  P a = circle[s], b = circle[t];
  return sqrt(sq(a.fi - b.fi) + sq(a.sec - b.sec));
}
double dist(P a, P b) { return sqrt(sq(a.fi - b.fi) + sq(a.sec - b.sec)); }
bool is_intersect(int s, int t) { return culc_dist(s, t) <= 2.0 + eps; }
P center_pos(int s, int t) {
  P a = circle[s], b = circle[t];
  return P((a.fi + b.fi) / 2, (a.sec + b.sec) / 2);
}
P normal_vector(int s, int t) {
  P a = circle[s], b = circle[t];
  return P(a.sec - b.sec, b.fi - a.fi);
}
P expand(int s, int t) {
  P n = normal_vector(s, t);
  double sin_x = sqrt(1 - (sq(culc_dist(s, t)) / 4));
  double len = sqrt(sq(n.fi) + sq(n.sec));
  return P(n.fi * sin_x / len, n.sec * sin_x / len);
}
int culc_covered(P p) {
  if (p.fi < 0 || p.fi > 10 || p.sec < 0 || p.sec > 10)
    return 0;
  int ret = 0;
  for (int i = 0; i < n; i++)
    if (dist(p, circle[i]) <= 1.0 + eps)
      ret++;
  return ret;
}
int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      return 0;
    ans = 1;
    for (int i = 0; i < n; i++)
      scanf("%lf,%lf", &circle[i].fi, &circle[i].sec);
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (!is_intersect(i, j))
          continue;
        P center = center_pos(i, j);
        P orientation = expand(i, j);
        ans = max(ans, culc_covered(P(center.fi - orientation.fi,
                                      center.sec - orientation.sec)));
        if (!(abs(orientation.fi) < eps && abs(orientation.sec) < eps))
          ans = max(ans, culc_covered(P(center.fi + orientation.fi,
                                        center.sec + orientation.sec)));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < eps)
const double K = 0.008;
double x[105], y[105];
int n;
double calc_dist(int id, double s, double t) {
  return sqrt((x[id] - s) * (x[id] - s) + (y[id] - t) * (y[id] - t));
}
int count(double s, double t) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (calc_dist(i, s, t) <= 1.0 + eps)
      res++;
  }
  return res;
}
int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int ans = 1;
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    for (int i = 0; i < n; i++)
      scanf("%lf,%lf", &x[i], &y[i]);
    for (double i = 0.0; i <= 10.0; i += K) {
      for (double j = 0.0; j <= 10.0; j += K) {
        ans = max(ans, count(i, j));
      }
    }
    cout << ans << endl;
  }
  return 0;
}