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

#include <complex>
#include <iostream>
#include <vector>
#define EPS 1.0e-10
using namespace std;
typedef double elem;
typedef complex<elem> point, vec;
inline elem dist(const point &a, const point &b) { return abs(a - b); }
inline vec normr(const vec &v) { return v * vec(0, -1); }
inline vec norml(const vec &v) { return v * vec(0, 1); }
inline vec unormr(const vec &v) { return normr(v) / abs(v); }
inline vec unorml(const vec &v) { return norml(v) / abs(v); }
int main() {
  while (true) {
    int ans = 1;
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    vector<point> points;
    for (int i = 0; i < n; ++i) {
      elem x, y;
      scanf("%lf%lf", &x, &y);
      points.push_back(point(x, y));
    }
    for (unsigned int i = 0; i < points.size(); ++i) {
      for (unsigned int j = i + 1; j < points.size(); ++j) {
        if (dist(points[i], points[j]) <= 2) {
          int count_p = 0;
          int count_q = 0;
          elem d = (elem)sqrt(1.0 - pow(dist(points[i], points[j]) / 2.0, 2.0));
          point p, q;
          vec ab = points[j] - points[i];
          point t = 0.5 * ab + points[i];
          p = d * unormr(ab) + t;
          q = d * unorml(ab) + t;
          // cout << i << "," << j << endl;
          for (unsigned int k = 0; k < points.size(); ++k) {
            // cout << dist(p,points[k]) << " " << dist(q,points[k]) << endl;

            if (dist(p, points[k]) <= 1 + EPS) {
              count_p++;
            }
            if (dist(q, points[k]) <= 1 + EPS) {
              count_q++;
            }
          }
          ans = max(ans, max(count_q, count_p));
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <complex>
#include <iostream>
#include <vector>
#define EPS 0.0001
using namespace std;
typedef long double elem;
typedef complex<elem> point, vec;
inline elem dist(const point &a, const point &b) { return abs(a - b); }
inline vec normr(const vec &v) { return v * vec(0, -1); }
inline vec norml(const vec &v) { return v * vec(0, 1); }
inline vec unormr(const vec &v) { return normr(v) / abs(v); }
inline vec unorml(const vec &v) { return norml(v) / abs(v); }
int main() {
  while (true) {
    int ans = 0;
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    vector<point> points;
    for (int i = 0; i < n; ++i) {
      elem x, y;
      scanf("%Lf%Lf", &x, &y);
      points.push_back(point(x, y));
    }
    for (unsigned int i = 0; i < points.size(); ++i) {
      for (unsigned int j = 0; j < points.size(); ++j) {
        if (i != j && dist(points[i], points[j]) < 2) {
          int count_p = 0;
          int count_q = 0;
          elem d = sqrt(1 - pow(dist(points[i], points[j]) / 2, 2));
          point p, q;
          vec ab = points[j] - points[i];
          point t = (long double)0.5 * ab + points[i];
          p = d * unormr(ab) + t;
          q = d * unorml(ab) + t;
          for (unsigned int k = 0; k < points.size(); ++k) {
            if (dist(p, points[k]) <= 1.0 + EPS) {
              count_p++;
            }
            if (dist(q, points[k]) <= 1.0 + EPS) {
              count_q++;
            }
          }
          ans = max(ans, max(count_q, count_p));
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}