Problem p00713 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>

#if 0
#define SPAM(a) printf a
#else
#define SPAM(a) (void)0
#endif

using namespace std;
const double EPS = 1e-5;
const double MAXDIST = 2.0;
const double MAXRAD = 1.0;

typedef pair<double, double> Point;

// TODO check all function good for double
// DONE check printf good for double
vector<Point> pointList;

using namespace std;

int inRange(Point A, Point B, double num) {
  double dx, dy, d;
  dx = A.first - B.first;
  dy = A.second - B.second;
  d = hypot(dx, dy);
  SPAM(("                    d = %lf\\n", d));
  if (abs(num - d) < 0.00001) {
    SPAM(("REALLY CLOSE\\n"));
  }
  if (EPS > d - num) {
    return 1;
  }
  return 0;
}

int get_Centre(Point pA, Point pB, Point &pC, Point &pD) {
  // SPAM(("in get Centre\\n"));
  double x0 = pA.first;
  double y0 = pA.second;
  double x1 = pB.first;
  double y1 = pB.second;

  double a, dx, dy, d, h, rx, ry;
  double x2, y2;

  /* dx and dy are the vertical and horizontal distances between
   * the circle centers.
   */
  dx = x1 - x0;
  dy = y1 - y0;
  // SPAM(("dx = %lf, dy = %lf\\n", dx, dyi));

  /* Determine the straight-line distance between the centers. */
  // d = sqrt((dy*dy) + (dx*dx));
  d = hypot(dx, dy); // Suggested by Keith Briggs
  // SPAM("         d = %lf\\n", d);

  /* Check for solvability. */
  if (EPS > MAXDIST - d) {
    /* no solution. circles do not intersect. */
    return 0;
  }
  // SPAM("check solvability\\n");

  /* 'point 2' is the point where the line through the circle
   * intersection points crosses the line between the circle
   * centers.
   */

  /* Determine the distance from point 0 to point 2. */
  a = (d / 2.0);
  // SPAM("a = %lf\\n", a);

  /* Determine the coordinates of point 2. */
  x2 = (x0 + x1) / 2.0;
  y2 = (y0 + y1) / 2.0;

  /* Determine the distance from point 2 to either of the
   * intersection points.
   */
  // SPAM("before sqrt\\n");
  // h = sqrt(1 - a*a);
  // SPAM("a*a = %lf\\n", a*a);

  h = sqrtl(MAXRAD - a * a);
  // SPAM("h = %lf\\n", h);
  // SPAM("after sqrt\\n");
  /* Now determine the offsets of the intersection points from
   * point 2.
   */
  // SPAM("get Offset\\n");
  // SPAM("          rx = -dy * (h / d) = %lf * (%lf /  %lf)\\n", -dy, h, d);
  // SPAM("          ry = dx * (h / d) = %lf * (%lf /  %lf)\\n", dx, h, d);
  rx = -dy * (h / d);
  ry = dx * (h / d);
  // SPAM("          rx = %lf, ry = %lf\\n", rx, ry);
  // SPAM("get int points\\n");
  /* Determine the absolute intersection points. */
  pC.first = x2 + rx;
  pC.second = y2 + ry;
  pD.first = x2 - rx;
  pD.second = y2 - ry;
  // SPAM("in getCentre pC = (%lf, %lf)\\n", pC.first, pC.second);

  return 1;
}

int main() {
  // for each iteration until 0
  int N;
  scanf("%d", &N);
  while (N != 0) {
    pointList.clear();
    // for each set of points
    for (int i = 0; i < N; i++) {
      // take in points
      double X, Y;
      scanf("%lf %lf", &X, &Y);
      pointList.push_back(make_pair(X, Y));
    }

    // SPAM("put all points in\\n");
    // setMax = 0
    int setMax = 0;
    // for each point
    for (int i = 0; i < N - 1; i++) {
      Point pA;
      pA = pointList[i];
      SPAM(("pA = (%lf, %lf)\\n", pA.first, pA.second));
      // for each second point (point1 -> fin)
      for (int j = i + 1; j < N; j++) {
        Point pB = pointList[j];

        // SPAM("finding centre\\n");
        // find centre
        Point pC, pD;
        // SPAM("--------> pB = (%lf,%lf)\\n", pB.first, pB.second);
        // continue if distance > 2
        if (get_Centre(pA, pB, pC, pD) == 0) {
          // SPAM("         not in range\\n");
          continue;
        }
        // SPAM("out getCentre pC = (%lf, %lf)\\n", pC.first, pC.second);
        // SPAM("after get_Centre\\n");
        // circleMax = 0;
        int circleCMax = 0;
        // SPAM("          going through points\\n");
        // go through all points
        for (auto p : pointList) {
          // see if centre-> point < 1, circleMax++
          SPAM(("                    p = (%lf, %lf)\\n", p.first, p.second));
          if (inRange(p, pC, MAXRAD)) {
            circleCMax++;
            SPAM(("                        in range\\n"));
          }
        }
        SPAM(("        circleCMax = %d\\n\\n", circleCMax));
        setMax = max(setMax, circleCMax);
        int circleDMax = 0;
        for (auto p : pointList) {
          // see if centre-> point < 1, circleMax++
          SPAM(("                    p = (%lf, %lf)\\n", p.first, p.second));
          if (inRange(p, pD, MAXRAD)) {
            circleDMax++;
            SPAM(("                        in range\\n"));
          }
        }
        SPAM(("        circleDMax = %d\\n\\n", circleDMax));
        setMax = max(setMax, circleDMax);
      }
    }
    // print setMax
    if (setMax == 0) {
      printf("1\\n");
    } else {
      printf("%d\\n", setMax);
    }

    // scan next N in
    scanf("%d", &N);
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 10;
typedef complex<double> point;
point a[N];
double kc[N][N];
int n;
int quetgoc(int i, double r, int n) {
  vector<pair<double, bool>> goc;
  for (int j = 0; j < n; j++) {
    if (kc[i][j] <= 2 * r && i != j) {
      double B = acos(kc[i][j] / (2 * r));
      double A = arg(a[j] - a[i]);
      double alpha = A - B;
      double beta = A + B;
      goc.push_back(make_pair(alpha, true));
      goc.push_back(make_pair(beta, false));
    }
  }
  sort(goc.begin(), goc.end());
  int cnt = 1, ans = 1;
  vector<pair<double, bool>>::iterator it;
  for (it = goc.begin(); it != goc.end(); ++it) {
    if ((*it).second)
      cnt++;
    else
      cnt--;
    if (cnt > ans)
      ans = cnt;
  }
  return ans;
}
int maxpoint(point a[], int n, int r) {
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      kc[i][j] = kc[j][i] = abs(a[i] - a[j]);
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans = max(ans, quetgoc(i, r, n));
  return ans;
}
signed main() {
  double x[10000], y[10000];
  int t;
  while (cin >> t && t != 0) {
    for (int i = 0; i < t; i++)
      a[i] = 0;
    for (int i = 0; i < t; i++)
      cin >> x[i] >> y[i];
    for (int i = 0; i < t; i++)
      a[i] = point(x[i], y[i]);
    int r = 1;
    cout << maxpoint(a, t, r) << endl;
  }
}