kartikkukreja / blog-codes

This is a repository for the codes that I write for my blog posts at http://kartikkukreja.wordpress.com.
MIT License
177 stars 117 forks source link

Bug in Graham Scan Convex Hull.cpp #3

Open lxxue opened 6 years ago

lxxue commented 6 years ago

I guess there is a bug in the implementation of Graham's Scan algorithm.

Try the following testcase: Input: { 0, 0 }, { 1, 1 }, { 2, 2 }, { 1, 4 } output: { 1, 4 }, { 2, 2 }, { 1, 1 }, { 0, 0 } correct output: { 1, 4 }, { 2, 2 }, { 0, 0 }

I believe the problem is in line 70: points[1] is not necessarily a vertex of convex hull if points[1] and points[2] have the same direction.

Btw: thank you for your wonderful blogs and readable code!

avighnac commented 1 year ago

Yeah, the convex hull code doesn't even pass on CSES, like bruh.