Convex Hull
InterviewTime limit1sMemory limit128 MB
Given points already labeled as hull or non-hull, output only the hull points in counterclockwise order starting from the lexicographically smallest one.
- Level
Medium4 of 10
- Topics
- Geometry, Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
Finding the convex hull of a set of points is a handy skill that comes up often. The task naturally splits into two stages: first, identify which points lie on the convex hull; second, arrange those hull points in counterclockwise order. Assume the first stage is already done — every point is already marked as being on the hull or not. Write a program that performs the second stage: list the hull points in counterclockwise order.
Input
The first line contains the number of points ().
Each of the next lines describes one point with three values , , and . Here and are integers whose absolute value is at most , and is the character Y or N: Y means the point lies on the convex hull, and N means it does not.
No two points coincide, and the points are not all collinear.
Output
On the first line, print the number of points that form the convex hull. Then print those points, one x y pair per line, arranged in counterclockwise order. The first point printed must be the one with the smallest -coordinate; if several points share that smallest -coordinate, choose among them the one with the smallest -coordinate.