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

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-6;
const double PI = acos(-1.0);

typedef complex<double> CP;
int N;
CP point[310];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    cin >> N;
    if (N == 0)
      break;
    REP(i, N) {
      double x, y;
      cin >> x >> y;
      point[i] = CP(x, y);
    }

    int ans = 1;
    for (int i1 = 0; i1 < N; ++i1) {
      for (int i2 = i1 + 1; i2 < N; ++i2) {
        double d = norm(point[i1] - point[i2]);
        if (sqrt(d) > 2.00) {
          continue;
        }
        CP m = (point[i1] + point[i2]) / 2.0;
        CP n = point[i2] - point[i1];
        n /= abs(n);
        n = CP(-imag(n), real(n));

        CP c = m + n * sqrt(1 - d / 4.0);
        int res = 2;
        for (int i = 0; i < N; ++i) {
          if (i == i1 || i == i2)
            continue;
          if (abs(c - point[i]) <= 1.0)
            ++res;
        }
        ans = max(ans, res);

        c = m - n * sqrt(1 - d / 4.0);
        res = 2;
        for (int i = 0; i < N; ++i) {
          if (i == i1 || i == i2)
            continue;
          if (abs(c - point[i]) <= 1.0)
            ++res;
        }
        ans = max(ans, res);
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

struct P {
  double x, y;
  bool operator<(const P &r) const { return x < r.x || (x == r.x && y < r.y); }
};
int N;
P point[310];

double dist(P &cir, int i) {
  return (cir.x - point[i].x) * (cir.x - point[i].x) +
         (cir.y - point[i].y) * (cir.y - point[i].y);
}

int cnt(P &c) {
  int res = 0;
  for (int i = 0; i < N; ++i)
    if (dist(c, i) <= 1.0)
      ++res;
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    cin >> N;
    if (N == 0)
      break;
    REP(i, N) cin >> point[i].x >> point[i].y;
    sort(point, point + N);

    int ans = 0;
    P c;
    for (int i1 = 0; i1 < N; ++i1) {
      for (int i2 = i1 + 1; i2 < N; ++i2) {
        for (int j1 = 0; j1 < N; ++j1) {
          for (int j2 = j1 + 1; j2 < N; ++j2) {
            c.x = (point[i1].x + point[i2].x) / 2.0;
            c.y = (point[j1].y + point[j2].y) / 2.0;
            ans = max(ans, cnt(c));
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}