-
(useless) getConvexHull232's competitive-programming templates. 2024. 8. 21. 16:00
linear inclusive?
can't just do ccw < 0 because if the polygon is line form some points get included in the hull twice (edge case)
upd : now all in Geometry..
Polygon getConvexHull(Polygon poly) { std::sort(poly.begin(), poly.end()); poly.resize(std::unique(poly.begin(), poly.end()) - poly.begin()); if (int(poly.size()) < 3) { return poly; } Polygon hull; for (int tries = 0; tries < 2; ++tries) { auto start = hull.size(); for (const auto& pt : poly) { while (hull.size() > start + 1 && ccw(hull[hull.size() - 2], hull.back(), pt) <= 0) { hull.pop_back(); } hull.push_back(pt); } hull.pop_back(); std::reverse(poly.begin(), poly.end()); } return hull; }
'232's competitive-programming templates.' 카테고리의 다른 글
LineContainer (0) 2024.08.22 (useless) MaximumFlow (Edmond Karp) (0) 2024.08.21 Point, Line, Polygon (0) 2024.08.21 SuffixArray (0) 2024.08.20 Graphs (0) 2024.08.17