Problem p03428 (C++)

Buggy submission (status: Runtime Error):
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF 1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-12
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline LL getint() {
  LL _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline LL add(LL _x, LL _y, LL _mod = mod7) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub(LL _x, LL _y, LL _mod = mod7) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul(LL _x, LL _y, LL _mod = mod7) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow(LL _a, LL _x, LL _mod) {
  if (_x == 0)
    return 1LL;
  LL _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1)
    _ret = mul(_ret, _a, _mod);
  return _ret;
}
LL mymul(LL _a, LL _x, LL _mod) {
  if (_x == 0)
    return 0LL;
  LL _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1)
    _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(D _x, D _y) { return _x > _y - eps && _x < _y + eps; }
void sleep(double sec = 1021) {
  clock_t s = clock();
  while (clock() - s < CLOCKS_PER_SEC * sec)
    ;
}
#define Bye exit(0)
int __ = 1, _cs;
/*********default*********/
typedef LL type;
typedef pair<type, type> Pt;
typedef pair<Pt, Pt> Line;
typedef pair<Pt, type> Circle;
#define X first
#define Y second
#define O first
#define R second
Pt operator+(const Pt &p1, const Pt &p2) { return {p1.X + p2.X, p1.Y + p2.Y}; }
Pt operator-(const Pt &p1, const Pt &p2) { return {p1.X - p2.X, p1.Y - p2.Y}; }
Pt operator*(const Pt &tp, const type &tk) { return {tp.X * tk, tp.Y * tk}; }
Pt operator/(const Pt &tp, const type &tk) { return {tp.X / tk, tp.Y / tk}; }
type operator*(const Pt &p1, const Pt &p2) { return p1.X * p2.X + p1.Y * p2.Y; }
type operator^(const Pt &p1, const Pt &p2) { return p1.X * p2.Y - p1.Y * p2.X; }
type norm2(const Pt &tp) { return tp * tp; }
double norm(const Pt &tp) { return sqrt(norm2(tp)); }
Pt perp(const Pt &tp) { return {-tp.Y, tp.X}; }
void scan(Pt &tp) { cin >> tp.X >> tp.Y; }
void build() {}
LL cross(Pt o, Pt a, Pt b) { return (a - o) ^ (b - o); }
vector<Pt> convex_hull(vector<Pt> pt) {
  sort(pt.begin(), pt.end());
  int top = 0;
  vector<Pt> stk(2 * pt.size());
  for (int i = 0; i < (int)pt.size(); i++) {
    while (top >= 2 && cross(stk[top - 2], stk[top - 1], pt[i]) < 0)
      top--;
    stk[top++] = pt[i];
  }
  for (int i = pt.size() - 2, t = top + 1; i >= 0; i--) {
    while (top >= t && cross(stk[top - 2], stk[top - 1], pt[i]) < 0)
      top--;
    stk[top++] = pt[i];
  }
  stk.resize(top - 1);
  return stk;
}
#define N 101
int n;
Pt p[N];
vector<Pt> vv;
void init() {
  n = getint();
  for (int i = 0; i < n; i++) {
    scan(p[i]);
    vv.push_back(p[i]);
  }
  vv = convex_hull(vv);
}
map<Pt, double> ans;
double vl[N];
void solve() {
  if (vv.size() == 1u) {
    ans[vv[0]] = 1.;
  } else if (vv.size() == 2u) {
    ans[vv[0]] = .5;
    ans[vv[1]] = .5;
  } else {
    double tot = 0.;
    for (size_t i = 0; i < vv.size(); i++) {
      Pt rgt = vv[(i + 1) % vv.size()];
      Pt lft = vv[(i + vv.size() - 1) % vv.size()];
      lft = perp(lft - vv[i]);
      rgt = perp(vv[i] - rgt);
      double theta =
          acosl(max(-1., min(1., (lft * rgt) / norm(lft) / norm(rgt))));
      vl[i] = theta;
      tot += vl[i];
    }
    for (size_t i = 0; i < vv.size(); i++)
      ans[vv[i]] = vl[i] / max(1., tot);
  }
  for (int i = 0; i < n; i++)
    printf("%.12f\n", ans[p[i]]);
}
int main() {
  build();
  //__ = getint();
  while (__--) {
    init();
    solve();
  }
}


Fixed submission:
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF 1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-12
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif
inline LL getint() {
  LL _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-')
    _tc = getchar();
  if (_tc == '-')
    _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9')
    _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline LL add(LL _x, LL _y, LL _mod = mod7) {
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub(LL _x, LL _y, LL _mod = mod7) {
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul(LL _x, LL _y, LL _mod = mod7) {
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow(LL _a, LL _x, LL _mod) {
  if (_x == 0)
    return 1LL;
  LL _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1)
    _ret = mul(_ret, _a, _mod);
  return _ret;
}
LL mymul(LL _a, LL _x, LL _mod) {
  if (_x == 0)
    return 0LL;
  LL _ret = mymul(add(_a, _a, _mod), _x >> 1, _mod);
  if (_x & 1)
    _ret = add(_ret, _a, _mod);
  return _ret;
}
inline bool equal(D _x, D _y) { return _x > _y - eps && _x < _y + eps; }
void sleep(double sec = 1021) {
  clock_t s = clock();
  while (clock() - s < CLOCKS_PER_SEC * sec)
    ;
}
#define Bye exit(0)
int __ = 1, _cs;
/*********default*********/
typedef LL type;
typedef pair<type, type> Pt;
typedef pair<Pt, Pt> Line;
typedef pair<Pt, type> Circle;
#define X first
#define Y second
#define O first
#define R second
Pt operator+(const Pt &p1, const Pt &p2) { return {p1.X + p2.X, p1.Y + p2.Y}; }
Pt operator-(const Pt &p1, const Pt &p2) { return {p1.X - p2.X, p1.Y - p2.Y}; }
Pt operator*(const Pt &tp, const type &tk) { return {tp.X * tk, tp.Y * tk}; }
Pt operator/(const Pt &tp, const type &tk) { return {tp.X / tk, tp.Y / tk}; }
type operator*(const Pt &p1, const Pt &p2) { return p1.X * p2.X + p1.Y * p2.Y; }
type operator^(const Pt &p1, const Pt &p2) { return p1.X * p2.Y - p1.Y * p2.X; }
type norm2(const Pt &tp) { return tp * tp; }
double norm(const Pt &tp) { return sqrt(norm2(tp)); }
Pt perp(const Pt &tp) { return {-tp.Y, tp.X}; }
void scan(Pt &tp) { cin >> tp.X >> tp.Y; }
void build() {}
LL cross(Pt o, Pt a, Pt b) { return (a - o) ^ (b - o); }
vector<Pt> convex_hull(vector<Pt> pt) {
  sort(pt.begin(), pt.end());
  int top = 0;
  vector<Pt> stk(2 * pt.size());
  for (int i = 0; i < (int)pt.size(); i++) {
    while (top >= 2 && cross(stk[top - 2], stk[top - 1], pt[i]) < 0)
      top--;
    stk[top++] = pt[i];
  }
  for (int i = pt.size() - 2, t = top + 1; i >= 0; i--) {
    while (top >= t && cross(stk[top - 2], stk[top - 1], pt[i]) < 0)
      top--;
    stk[top++] = pt[i];
  }
  stk.resize(top - 1);
  return stk;
}
#define N 101
int n;
Pt p[N];
vector<Pt> vv;
void init() {
  n = getint();
  for (int i = 0; i < n; i++) {
    scan(p[i]);
    vv.push_back(p[i]);
  }
  vv = convex_hull(vv);
}
map<Pt, double> ans;
double vl[N + N];
void solve() {
  if (vv.size() == 1u) {
    ans[vv[0]] = 1.;
  } else if (vv.size() == 2u) {
    ans[vv[0]] = .5;
    ans[vv[1]] = .5;
  } else {
    double tot = 0.;
    for (size_t i = 0; i < vv.size(); i++) {
      Pt rgt = vv[(i + 1) % vv.size()];
      Pt lft = vv[(i + vv.size() - 1) % vv.size()];
      lft = perp(lft - vv[i]);
      rgt = perp(vv[i] - rgt);
      double theta =
          acosl(max(-1., min(1., (lft * rgt) / norm(lft) / norm(rgt))));
      vl[i] = theta;
      tot += vl[i];
    }
    for (size_t i = 0; i < vv.size(); i++)
      ans[vv[i]] = vl[i] / max(1., tot);
  }
  for (int i = 0; i < n; i++)
    printf("%.12f\n", ans[p[i]]);
}
int main() {
  build();
  //__ = getint();
  while (__--) {
    init();
    solve();
  }
}