Problem p00713 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

constexpr long double EPS = 10e-6;
constexpr long double radius = 1.0 + EPS;
constexpr long double diameter = 2.0 + EPS;

class Point {
public:
  long double x, y;
  Point(long double x = 0.0, long double y = 0.0) : x(x), y(y) {}
  Point operator+(Point p) const { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) const { return Point(x - p.x, y - p.y); }
  Point operator*(long double a) const { return Point(x * a, y * a); }
  Point operator/(long double a) const { return Point(x / a, y / a); }
  long double norm() const { return x * x + y * y; }
  long double dot(Point p) const { return x * p.x + y * p.y; }
};

int main() {
  int n;
  while (scanf("%d", &n) && n) {
    vector<Point> points(n);
    rep(n) scanf("%Lf %Lf", &points[i].x, &points[i].y);

    int ans = 1, tmp;
    Point mid, midv, center;
    long double c;
    rep(n) {
      repp(j, n) {
        if (j == i)
          continue;
        mid = points[j] - points[i];
        if (mid.norm() > diameter * diameter)
          continue;
        mid = mid * 0.5;
        midv = Point(mid.y, -mid.x);
        c = sqrt((1.0 - mid.norm()) / midv.norm());
        center = points[i] + mid + midv * c;
        tmp = 0;
        for (Point p : points) {
          Point v = p - center;
          if (v.norm() <= radius)
            tmp++;
        }
        ans = max(tmp, ans);
      }
    }
    printf("%d\n", ans);
    debug(ans);
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

constexpr long double EPS = 10e-6;
constexpr long double radius = 1.0 + EPS;
constexpr long double diameter = 2.0 + EPS;

class Point {
public:
  long double x, y;
  Point(long double x = 0.0, long double y = 0.0) : x(x), y(y) {}
  Point operator+(Point p) const { return Point(x + p.x, y + p.y); }
  Point operator-(Point p) const { return Point(x - p.x, y - p.y); }
  Point operator*(long double a) const { return Point(x * a, y * a); }
  Point operator/(long double a) const { return Point(x / a, y / a); }
  long double norm() const { return x * x + y * y; }
  long double dot(Point p) const { return x * p.x + y * p.y; }
};

int main() {
  int n;
  while (scanf("%d", &n) && n) {
    vector<Point> points(n);
    rep(n) scanf("%Lf %Lf", &points[i].x, &points[i].y);

    int ans = 1, tmp;
    Point mid, midv, center;
    long double c;
    rep(n) {
      repp(j, n) {
        if (j == i)
          continue;
        mid = points[j] - points[i];
        if (mid.norm() > diameter * diameter)
          continue;
        mid = mid * 0.5;
        midv = Point(mid.y, -mid.x);
        c = sqrt((1.0 - mid.norm()) / midv.norm());
        center = points[i] + mid + midv * c;
        tmp = 0;
        for (Point p : points) {
          Point v = p - center;
          if (v.norm() <= radius)
            tmp++;
        }
        ans = max(tmp, ans);
      }
    }
    printf("%d\n", ans);
  }
}