#include #include #include #include using namespace std; typedef pair PII; typedef vector VII; PII operator-(PII a, PII b) { return {a.first-b.first, a.second-b.second}; } int cross(PII a, PII b) { return a.first*b.second - a.second*b.first; } VII graham_scan(VII points) { int n=points.size(); PII t=*min_element(points.begin(), points.end()); vector> angles; for (PII p : points) if (p!=t) { PII v = p-t; angles.push_back({atan2(v.second, v.first), p}); } sort(angles.begin(), angles.end()); vector hull = {t}; for (auto [_, c] : angles) { while (hull.size()>=2) { PII a=hull[hull.size()-2], b=hull[hull.size()-1]; PII ab=b-a, ac=c-a; if (cross(ab,ac)>0) break; hull.pop_back(); } hull.push_back(c); } return hull; } int main() { vector points = {{4,0}, {2,3}, {5,2}, {6,1}, {8,4}, {6,6}, {5,4}, {4,5}, {2,6}, {1,1}, {1,5}, {3,2}}; auto hull = graham_scan(points); for (auto [x,y] : hull) cout << x << ", " << y << endl; return 0; }