void convex_hull(points &a, points &res) { res.resize(2 * a.size() + 10); sort(a.begin(), a.end(), cmpxy); a.erase(unique(a.begin(), a.end()), a.end()); int m = 0; for (int i = 0; i < (int)a.size(); i ++) { while(m > 1 && dcmp(det(res[m - 1] - res[m - 2], a[i] - res[m - 2])) <= 0) --m; res[m++] = a[i]; } int k = m; for (int i = (int)a.size() - 2; i >= 0; i --) { while(m > k && dcmp(det(res[m - 1] - res[m - 2], a[i] - res[m - 2])) <= 0) --m; res[m++] = a[i]; } res.resize(m); //if (a.size() > 1) res.resize(m - 1); }
points convexHull (points a) { points up,dw; sort (a.begin(), a.end()); for (int i=0;i<a.size();i++) { while (up.size()>=2 && ccw(*++up.rbegin(),*up.rbegin(),a[i])>=0) up.pop_back(); while (dw.size()>=2 && ccw(*++dw.rbegin(),*dw.rbegin(),a[i])<=0) dw.pop_back(); up.emplace_back(a[i]); dw.emplace_back(a[i]); } up.insert (up.end(), ++dw.rbegin(), --dw.rend()); return up; }