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

#include <cmath>
#include <iostream>

using namespace std;

#define EPS 1e-5

struct point {
  double x;
  double y;
};

struct line {
  double a; // 傾き
  double b; // y切片
};

istream &operator>>(istream &s, point &p);
bool get_line(const point &a, const point &b, line *a_b);
bool get_position(const point &a, const point &b, const point &c);
bool get_cross(const point &a, const point &b, const point &c, const point &d);
bool get_convex(const point &a, const point &b, const point &c, const point &d);
bool get_convex_new(const point &a, const point &b, const point &c,
                    const point &d);

int main(void) {
  point a, b, c, d;
  char comma;

  while (1) {
    cin >> a >> comma >> b >> comma >> c >> comma >> d;
    if (cin.eof())
      break;
    if (get_convex_new(a, b, c, d))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}

istream &operator>>(istream &s, point &p) {
  char c;
  return s >> p.x >> c >> p.y;
}

bool get_line(const point &a, const point &b, line *a_b) {
  if (fabs(a.x - b.x) < EPS)
    return false;
  else {
    a_b->a = (a.y - b.y) / (a.x - b.x);
    a_b->b = a.y - (a.x * a_b->a);
    return true;
  }
}

bool get_position(const point &a, const point &b, const point &c) {
  // 点a, bを通る直線に対する点cの位置を返す。(右、上：ture)

  line a_b;

  bool result = get_line(a, b, &a_b);
  if (result == false) {
    if (c.x > a.x)
      return true;
    else
      return false;
  } else {
    if (c.y > a_b.a * c.x + a_b.b)
      return true;
    else
      return false;
  }
}

bool get_cross(const point &a, const point &b, const point &c, const point &d) {
  // 点a, cを結ぶ線分と、点b, dを通る直線とが交わればtrueを返す。

  bool result_ac_b = get_position(a, c, b);
  bool result_ac_d = get_position(a, c, d);
  if (result_ac_b == result_ac_d)
    return false;
  else
    return true;
}

bool get_convex(const point &a, const point &b, const point &c,
                const point &d) {
  // 点a, b, c, dの順に結んだ時にできる四角形が凸であればtrueを返す。

  bool result_ac_bd = get_cross(a, b, c, d); // 線分acと直線bdの交差判定
  bool result_bd_ac = get_cross(b, a, d, c); // 線分bdと直線acの交差判定

  if (result_ac_bd == true && result_bd_ac == true)
    return true;
  else
    return false;
}

bool get_convex_new(const point &a, const point &b, const point &c,
                    const point &d) {
  bool result_ac_bd;
  bool result_bd_ac;

  if (get_position(a, c, b) != get_position(a, c, d))
    result_ac_bd = true;
  else
    result_ac_bd = false;

  if (get_position(b, d, a) != get_position(b, d, c))
    result_bd_ac = true;
  else
    result_bd_ac = false;

  if (result_ac_bd == true && result_bd_ac == true)
    return true;
  else
    return false;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

struct point {
  double x;
  double y;
};

istream &operator>>(istream &s, point &p) { return s >> p.x >> p.y; }

bool get_convex(const point &a, const point &b, const point &c,
                const point &d) {
  point a_c, a_b, a_d;
  point b_d, b_a, b_c;

  a_c.x = c.x - a.x;
  a_c.y = c.y - a.y;
  a_b.x = b.x - a.x;
  a_b.y = b.y - a.y;
  a_d.x = d.x - a.x;
  a_d.y = d.y - a.y;
  b_d.x = d.x - b.x;
  b_d.y = d.y - b.y;
  b_a.x = a.x - b.x;
  b_a.y = a.y - b.y;
  b_c.x = c.x - b.x;
  b_c.y = c.y - b.y;

  bool result_a, result_b;

  result_a =
      ((a_c.x * a_b.y - a_b.x * a_c.y) * (a_c.x * a_d.y - a_d.x * a_c.y) < 0);
  result_b =
      ((b_d.x * b_a.y - b_a.x * b_d.y) * (b_d.x * b_c.y - b_c.x * b_d.y) < 0);

  if (result_a == true && result_b == true)
    return true;
  else
    return false;
}

int main(void) {
  point a, b, c, d;

  while (1) {
    cin >> a >> b >> c >> d;
    if (cin.eof())
      break;
    if (get_convex(a, b, c, d))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}