Monotone chain convex hull.cpp

using namespace std;
 * 1) include
 * 2) include
 * 3) include


 * 1) define EPS 1e-8

struct pt { double x,y; };

bool operator <(pt p, pt q) { return p.x hull(vector p) { if (p.size <= 1) return p;

sort(p.begin, p.end); p.erase(unique(p.begin, p.end), p.end);

int n = p.size, k = 0; vector h;

for (int i = 0; i < n; i++) { while (k >= 2 && skew(h[k-2], h[k-1], p[i]) < EPS) k--, h.pop_back; k++, h.push_back(p[i]); }

for (int i = n-2, t = k+1; i >= 0; i--) { while (k >= t && skew(h[k-2], h[k-1], p[i]) < EPS) k--, h.pop_back; k++, h.push_back(p[i]); }

return h; }