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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(v, c) for (auto &v : c)

#define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()
#define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

const double EPS = 1e-9;

struct Point {
  double x, y;

  Point() : x(0), y(0) {}
  Point(const double x, const double y) : x(x), y(y) {}
  Point(const Point &a) : x(a.x), y(a.y) {}

  const Point operator+(const Point &a) const {
    return Point(x + a.x, y + a.y);
  }

  Point &operator+=(const Point &a) {
    x += a.x;
    y += a.y;

    return *this;
  }

  const Point operator-(const Point &a) const {
    return Point(x + (-a.x), y + (-a.y));
  }

  Point &operator-=(const Point &a) {
    x -= a.x;
    y -= a.y;

    return *this;
  }

  const Point operator*(const double a) const { return Point(x * a, y * a); }

  Point &operator*=(const double a) {
    x *= a;
    y *= a;

    return *this;
  }

  const Point operator/(const double a) const { return Point(x / a, y / a); }

  Point &operator/=(const double a) {
    x /= a;
    y /= a;

    return *this;
  }

  bool operator<(const Point &a) const { return x == a.x ? y < a.y : x < a.x; }

  double abs() const { return sqrt(pow(x, 2.) + pow(y, 2.)); }

  const Point unitVector() const { return *this / abs(); }

  const Point normalVector1() const { return Point(y, -x); }

  const Point normalVector2() const { return Point(-y, x); }
};

// 二点間の距離
double distance(const Point &a, const Point &b) { return (a - b).abs(); }

// 外積（クロス積）
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }

// 直線 ( p1, p2 ) と直線 ( q1, q2 ) の交点
Point lines_intersection(const Point &p1, const Point &p2, const Point &q1,
                         const Point &q2) {
  return p1 + (p2 - p1) * (cross(q2 - q1, q1 - p1) / cross(q2 - q1, p2 - p1));
}

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

  cout << setprecision(3) << fixed;

  int n;
  cin >> n;

  REP(casenum, 0, n) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    Point A(x1, y1), B(x2, y2), C(x3, y3);
    double a = distance(B, C), b = distance(C, A), c = distance(A, B);

    Point midAB = (A + B) / 2;
    Point midAC = (A + C) / 2;

    Point p = lines_intersection(midAB, midAB + (B - A).normalVector1(), midAC,
                                 midAC + (C - A).normalVector1());

    double cosA = (pow(b, 2.) + pow(c, 2.) - pow(a, 2.)) / (2 * b * c);
    double sinA = sin(acos(cosA));
    double r = abs(a) / abs(sinA) / 2;

    cout << p.x << ' ' << p.y << ' ' << r << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define EACH(v, c) for (auto &v : c)

#define ITER(c) __typeof((c).begin())
#define IREP(c, it) for (ITER(c) it = c.begin(); it != c.end(); ++it)
#define ALL(c) (c).begin(), (c).end()

#define PB(n) push_back(n)
#define MP(a, b) make_pair((a), (b))
#define EXIST(c, e) ((c).find(e) != (c).end())

#define fst first
#define snd second

#define DUMP(x) cerr << #x << " = " << (x) << endl
#define DEBUG(x)                                                               \\
  cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl

const double EPS = 1e-9;

struct Point {
  double x, y;

  Point() : x(0), y(0) {}
  Point(const double x, const double y) : x(x), y(y) {}
  Point(const Point &a) : x(a.x), y(a.y) {}

  Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }

  Point &operator+=(const Point &a) {
    x += a.x;
    y += a.y;

    return *this;
  }

  Point operator-(const Point &a) const {
    return Point(x + (-a.x), y + (-a.y));
  }

  Point &operator-=(const Point &a) {
    x -= a.x;
    y -= a.y;

    return *this;
  }

  Point operator*(const double &a) const { return Point(x * a, y * a); }

  Point &operator*=(const double &a) {
    x *= a;
    y *= a;

    return *this;
  }

  Point operator/(const double &a) const { return Point(x / a, y / a); }

  Point &operator/=(const double &a) {
    x /= a;
    y /= a;

    return *this;
  }

  bool operator<(const Point &a) const { return x == a.x ? y < a.y : x < a.x; }

  double abs() const { return sqrt(pow(x, 2.) + pow(y, 2.)); }
};

double distance(const Point &a, const Point &b) {
  return sqrt(pow(a.x - b.x, 2.) + pow(a.y - b.y, 2.));
}

bool eq(const double &a, const double &b) { return abs(a - b) <= EPS; }

void solve() {
  Point A, B, C;

  cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y;
  double a = distance(B, C), b = distance(C, A), c = distance(A, B);

  double cosA = (pow(b, 2.) + pow(c, 2.) - pow(a, 2.)) / (2 * b * c);
  double sinA = sin(acos(cosA));
  double r = abs(a / sinA) / 2;

  Point midAB = (A + B) / 2, AB = B - A;
  Point normAB = Point(AB.y, -AB.x);
  normAB /= normAB.abs();

  double AM = distance(A, midAB);
  double t = sqrt(pow(r, 2.) - pow(AM, 2.));
  Point res1;

  if (eq(distance(midAB + normAB * t, A), distance(midAB + normAB * t, C))) {
    res1 = midAB + normAB * t;
  } else if (eq(distance(midAB + normAB * -t, A),
                distance(midAB + normAB * -t, C))) {
    res1 = midAB + normAB * -t;
  } else {
    abort();
  }

  cout << res1.x << ' ' << res1.y << ' ' << r << endl;

  return;
}

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

  cout.precision(3);
  cout << fixed;

  int n;
  cin >> n;

  REP(i, 0, n) { solve(); }

  return 0;
}