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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef complex<long double> P;
typedef pair<P, P> L;
#define X real()
#define Y imag()
#define EPS (long double)(1e-10)

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

long double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
long double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }

P intersection(L a, L b) {
  // 直線aと直線bの交点
  return a.first + cross(b.second - b.first, a.first - b.first) /
                       (-cross(b.second - b.first, a.second - b.first) +
                        cross(b.second - b.first, a.first - b.first)) *
                       (a.second - a.first);
}

long double p_to_l_dist(P a, L s) {
  return abs(cross(s.first - s.second, a - s.second)) / abs(s.first - s.second);
}

L angle_bisector(P a, P b, P c) {
  // 角abcをの二等分線
  // a, b or b, cが一致するとゼロ徐算が発生しREになる
  P p = b + (a - b) / abs(a - b) * (long double)100.0 +
        (c - b) / abs(c - b) * (long double)100.0;
  return L(b, p);
}

P n_vector(P a) {
  // aベクトルに垂直な単位ベクトル
  long double l = abs(a);
  return P(-a.Y, a.X) / l;
}

int main() {
  int n;
  while (cin >> n, n) {
    long double x1, x2, y1, y2;
    vector<L> V;
    for (int i = 0; i < n; ++i) {
      cin >> x1 >> y1 >> x2 >> y2;
      V.emplace_back(P(x1, y1), P(x2, y2));
    }
    if (n < 3) {
      cout << "Many" << endl;
      continue;
    }
    vector<L> A, B;
    vector<P> C, D;

    for (int j = 1; j < n; ++j) {
      if (abs(cross(V[0].first - V[0].second, V[j].first - V[j].second)) <
          EPS) {
        A.emplace_back((V[0].first + V[j].first) / (long double)2.0,
                       (V[0].first + V[j].first) / (long double)2.0 +
                           V[0].second - V[0].first);
        B.emplace_back(A.back());
      } else {
        P c = intersection(V[0], V[j]);
        A.push_back(angle_bisector(c + V[0].first - V[0].second, c,
                                   c + V[j].first - V[j].second));
        P a = A.back().first,
          v = n_vector(A.back().second - a) * (long double)100.0;
        B.emplace_back(a, a + v);
      }
    }

    for (int i = 1; i < A.size(); ++i) {
      if (abs(cross(A[0].first - A[0].second, A[i].first - A[i].second)) >
          EPS) {
        C.push_back(intersection(A[0], A[i]));
      } else if (p_to_l_dist(A[i].second, A[0]) < EPS &&
                 p_to_l_dist(A[i].second, A[0]) < EPS) {
        C.push_back(A[i].first);
        C.push_back(A[i].second);
      }
      if (abs(cross(A[0].first - A[0].second, B[i].first - B[i].second)) >
          EPS) {
        C.push_back(intersection(A[0], B[i]));
      } else if (p_to_l_dist(B[i].second, A[0]) < EPS &&
                 p_to_l_dist(B[i].second, A[0]) < EPS) {
        C.push_back(B[i].first);
        C.push_back(B[i].second);
      }
      if (abs(cross(B[0].first - B[0].second, A[i].first - A[i].second)) >
          EPS) {
        C.push_back(intersection(B[0], A[i]));
      } else if (p_to_l_dist(A[i].second, B[0]) < EPS &&
                 p_to_l_dist(A[i].second, B[0]) < EPS) {
        C.push_back(A[i].first);
        C.push_back(A[i].second);
      }
      if (abs(cross(B[0].first - B[0].second, B[i].first - B[i].second)) >
          EPS) {
        C.push_back(intersection(B[0], B[i]));
      } else if (p_to_l_dist(B[i].second, B[0]) < EPS &&
                 p_to_l_dist(B[i].second, B[0]) < EPS) {
        C.push_back(B[i].first);
        C.push_back(B[i].second);
      }
    }
    for (int i = 0; i < C.size(); ++i) {
      P c = C[i];
      long double d = p_to_l_dist(c, V[0]);
      bool f = true;
      for (int j = 1; j < n; ++j) {
        if (abs(p_to_l_dist(c, V[j]) - d) > EPS) {
          f = false;
          break;
        }
      }
      if (f && (D.empty() || abs(D.back() - c) > EPS)) {
        D.push_back(c);
        if (D.size() > 1)
          break;
      }
    }
    if (D.size() == 0)
      cout << "None" << endl;
    else if (D.size() == 1)
      printf("%.12Lf %.12Lf\\n", D[0].X, D[0].Y);
    else
      cout << "Many" << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <complex>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P, P> L;
#define X real()
#define Y imag()
#define EPS (1e-10)

double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }
double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }

P intersection(L a, L b) {
  // 直線aと直線bの交点
  return a.first + cross(b.second - b.first, a.first - b.first) /
                       (-cross(b.second - b.first, a.second - b.first) +
                        cross(b.second - b.first, a.first - b.first)) *
                       (a.second - a.first);
}

double p_to_l_dist(P a, L s) {
  return abs(cross(s.first - s.second, a - s.second)) / abs(s.first - s.second);
}

L angle_bisector(P a, P b, P c) {
  // 角abcをの二等分線
  // a, b or b, cが一致するとゼロ徐算が発生しREになる
  P p = b + (a - b) / abs(a - b) + (c - b) / abs(c - b);
  return L(b, p);
}

P n_vector(P a) {
  // aベクトルに垂直な単位ベクトル
  double l = abs(a);
  return P(-a.Y, a.X) / l;
}

int main() {
  int n;
  while (cin >> n, n) {
    double x1, x2, y1, y2;
    vector<L> V;
    for (int i = 0; i < n; ++i) {
      cin >> x1 >> y1 >> x2 >> y2;
      V.emplace_back(P(x1, y1), P(x2, y2));
    }
    vector<L> A, B;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (abs(cross(V[i].first - V[i].second, V[j].first - V[j].second)) <
            EPS) {
          A.emplace_back((V[i].first + V[j].first) / 2.0,
                         (V[i].second + V[j].second) / 2.0);
        } else {
          P c = intersection(V[i], V[j]);
          // cout << "intersection " << i << " " << j << " "  << c << endl;
          if (abs(c - V[i].first) > EPS && abs(c - V[j].first)) {
            A.push_back(angle_bisector(V[i].first, c, V[j].first));
          } else if (abs(c - V[i].first) > EPS) {
            A.push_back(angle_bisector(V[i].first, c, V[j].second));
          } else if (abs(c - V[j].first)) {
            A.push_back(angle_bisector(V[i].second, c, V[j].first));
          } else {
            A.push_back(angle_bisector(V[i].second, c, V[j].second));
          }
          P a = A.back().first, v = n_vector(A.back().second - a);
          B.emplace_back(a, a + v);
        }
      }
    }
    if (A.size() < 2) {
      cout << "Many" << endl;
      continue;
    }
    vector<P> C;
    if (abs(cross(A[0].first - A[0].second, A[1].first - A[1].second)) > EPS) {
      C.push_back(intersection(A[0], A[1]));
    }
    if (abs(cross(A[0].first - A[0].second, B[1].first - B[1].second)) > EPS) {
      C.push_back(intersection(A[0], B[1]));
    }
    if (abs(cross(B[0].first - B[0].second, A[1].first - A[1].second)) > EPS) {
      C.push_back(intersection(B[0], A[1]));
    }
    if (abs(cross(B[0].first - B[0].second, B[1].first - B[1].second)) > EPS) {
      C.push_back(intersection(B[0], B[1]));
    }
    if (C.size() < 1) {
      cout << "None" << endl;
    }
    bool g = true;
    for (int j = 0; j < C.size(); ++j) {
      P c = C[j];
      bool f = true;
      for (int i = 0; i < A.size(); ++i) {
        if (p_to_l_dist(c, A[i]) > EPS && p_to_l_dist(c, B[i]) > EPS) {
          f = false;
          break;
        }
      }
      if (f) {
        printf("%.12f %.12f\\n", c.X, c.Y);
        g = false;
        break;
      }
    }
    if (g)
      cout << "None" << endl;
  }
  return 0;
}