Problem p03428 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 10;
const double eps = 1e-7;
const double pi = acos(-1.0);
int n;
struct Point {
  ll x, y;
  int id;
  Point() = default;
  Point(const ll &_x, const ll &_y) : x(_x), y(_y) {}
} p[maxn];
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
ll cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
ll dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
double len(const Point &a) { return sqrt(dot(a, a)); }
double clip(double x) { return max(min(x, 1.0), -1.0); }
double angle(const Point &a, const Point &b) {
  return acos(clip(1.0 * dot(a, b) / (len(a) * len(b))));
}
double ans[maxn];
bool cmp(const Point &a, const Point &b) {
  auto ret = cross(a - p[1], b - p[1]) > 0;
  return ret > 0 || (ret == 0 && a.x < b.x);
}
void convex() {
  int pos = 1;
  for (int i = 2; i <= n; ++i)
    if (p[i].x < p[pos].x || (p[i].x == p[pos].x && p[i].y < p[pos].y))
      pos = i;
  swap(p[pos], p[1]);
  sort(p + 2, p + n + 1, cmp);
  vector<Point> ret = {p[1]};
  for (int i = 2; i <= n; ++i) {
    while (ret.size() >= 2 && cross(p[i] - ret[ret.size() - 2],
                                    ret.back() - ret[ret.size() - 2]) >= 0)
      ret.pop_back();
    ret.push_back(p[i]);
  }
  for (int i = 0; i < ret.size(); ++i)
    ans[ret[i].id] =
        0.5 - angle(ret[(i + 1) % ret.size()] - ret[i],
                    ret[(i - 1 + ret.size()) % ret.size()] - ret[i]) /
                  (2 * pi);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i].x >> p[i].y;
    p[i].id = i;
  }
  convex();
  for (int i = 1; i <= n; ++i)
    printf("%.10lf\n", ans[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 10;
const double eps = 1e-7;
const double pi = acos(-1.0);
int n;
struct Point {
  ll x, y;
  int id;
  Point() = default;
  Point(const ll &_x, const ll &_y) : x(_x), y(_y) {}
} p[maxn];
Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
ll cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
ll dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
double len(const Point &a) { return sqrt(dot(a, a)); }
double clip(double x) { return max(min(x, 1.0), -1.0); }
double angle(const Point &a, const Point &b) {
  return acos(clip(1.0 * dot(a, b) / (len(a) * len(b))));
}
double ans[maxn];
bool cmp(const Point &a, const Point &b) {
  auto ret = cross(a - p[1], b - p[1]);
  return ret > 0 || (ret == 0 && a.x < b.x);
}
void convex() {
  int pos = 1;
  for (int i = 2; i <= n; ++i)
    if (p[i].x < p[pos].x || (p[i].x == p[pos].x && p[i].y < p[pos].y))
      pos = i;
  swap(p[pos], p[1]);
  sort(p + 2, p + n + 1, cmp);
  vector<Point> ret = {p[1]};
  for (int i = 2; i <= n; ++i) {
    while (ret.size() >= 2 && cross(p[i] - ret[ret.size() - 2],
                                    ret.back() - ret[ret.size() - 2]) >= 0)
      ret.pop_back();
    ret.push_back(p[i]);
  }
  for (int i = 0; i < ret.size(); ++i)
    ans[ret[i].id] =
        0.5 - angle(ret[(i + 1) % ret.size()] - ret[i],
                    ret[(i - 1 + ret.size()) % ret.size()] - ret[i]) /
                  (2 * pi);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i].x >> p[i].y;
    p[i].id = i;
  }
  convex();
  for (int i = 1; i <= n; ++i)
    printf("%.10lf\n", ans[i]);
  return 0;
}