Problem p03428 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
typedef long long int ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for (int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...)                                                               \
  if (LOG_F)                                                                   \
  fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n) { return n == 0 ? 1 : x * pow(x, n - 1); }

/*
n
x1 y1
..
xn yn

M PI
 */
int n;
long double x[100], y[100], theta[100];

int main() {
  cin >> n;

  if (n == 2) {
    REP(i, 2) { cout << 0.5 << endl; }
    return 0;
  }

  REP(i, n) { cin >> x[i] >> y[i]; }

  REP(i, n) {
    long double t[100], dt[100];

    REP(j, n) {
      if (j == i)
        continue;
      int j1 = j < i ? j : j - 1;

      if (x[j] - x[i] == 0.0) {
        t[j1] = y[j] - y[i] > 0 ? M_PI / 2 : -M_PI / 2;
      } else {
        t[j1] = atan((y[j] - y[i]) / (x[j] - x[i]));
        if (x[j] - x[i] < 0)
          t[j1] = t[j1] + M_PI;
        if (t[j1] > M_PI)
          t[j1] -= 2 * M_PI;
      }
      LOG("t[%d]=%Lf\n", j1, t[j1]);
    }
    sort(t, t + n - 1);

    REP(j, n - 2) {
      dt[j] = t[j + 1] - t[j];
      LOG("dt[%d]=%Lf\n", j, dt[j]);
    }
    dt[n - 2] = 2 * M_PI - (t[n - 2] - t[0]);
    LOG("dt[%d]=%Lf\n", n - 1, dt[n - 1]);

    sort(dt, dt + n, greater<long double>());

    long double x = dt[0] - M_PI;

    if (x <= 0) {
      cout << 0 << endl;
    } else {
      cout << x / (2 * M_PI) << endl;
    }
  }

  return 0;
}


Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
typedef long long int ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for (int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...)                                                               \
  if (LOG_F)                                                                   \
  fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n) { return n == 0 ? 1 : x * pow(x, n - 1); }

/*
n
x1 y1
..
xn yn

M PI
 */
int n;
long double x[100], y[100], theta[100];

int main() {
  cin >> n;

  if (n == 2) {
    REP(i, 2) { cout << 0.5 << endl; }
    return 0;
  }

  REP(i, n) { cin >> x[i] >> y[i]; }

  REP(i, n) {
    long double t[100], dt[100];

    REP(j, n) {
      if (j == i)
        continue;
      int j1 = j < i ? j : j - 1;

      if (x[j] - x[i] == 0.0) {
        t[j1] = y[j] - y[i] > 0 ? M_PI / 2 : -M_PI / 2;
      } else {
        t[j1] = atan((y[j] - y[i]) / (x[j] - x[i]));
        if (x[j] - x[i] < 0)
          t[j1] = t[j1] + M_PI;
        if (t[j1] > M_PI)
          t[j1] -= 2 * M_PI;
      }
      LOG("t[%d]=%Lf\n", j1, t[j1]);
    }
    sort(t, t + n - 1);

    REP(j, n - 2) {
      dt[j] = t[j + 1] - t[j];
      LOG("dt[%d]=%Lf\n", j, dt[j]);
    }
    dt[n - 2] = 2 * M_PI - (t[n - 2] - t[0]);
    LOG("dt[%d]=%Lf\n", n - 2, dt[n - 2]);

    sort(dt, dt + n, greater<long double>());

    long double x = dt[0] - M_PI;

    if (x <= 0) {
      cout << 0 << endl;
    } else {
      cout << x / (2 * M_PI) << endl;
    }
  }

  return 0;
}