Editorial for ECOO '21 P5 - Waldwick's Walk


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: AQT

The problem is asking to find all the vertices to a non-degenerate convex polygon. We can try to find all the vertices by asking the judge a point (x, y) in which we get any vertex of the polygon that is closest to (x, y).

For the first subtask all the range of points that could be on the polygon is small ((10 - (-10) + 1)^2 = 441 possible candidates). A sufficient algorithm for the first subtask is to query all points in the range and maintain a counter of all the times the queried point is equal to the point that has been returned.

For the other subtask, we note that a convex polygon must have two points (x_1, y_1) and (x_2, y_2) such that y_1 \ne y_2. This means that the smallest y-coordinate is not the same as the largest y-coordinate. We can get those two points by querying points (0, -10^{18}) and (0, 10^{18}) for the vertex with the smallest and largest y-coordinate of the polygon.

Now consider, this method of constructing a polygon, knowing that we have at least 2 vertices u and v. We will now check if u and v are adjacent. For u and v to be adjacent, then all the vertices must strictly lie on one side of the line u and v. So, if there exist a point on the other side of the line, then u and v are not adjacent. We can try to find this point by using the following method.

  1. Let m be the midpoint of the line segment u and v.
  2. Draw a ray r that is perpendicular to the line segment u and v from m and extends towards the plane where a new point might potentially exist (the half-plane that does not contain the rest of the known points of the convex polygon).
  3. Let q be some point on the ray where either the absolute value of its x or y value is large and query that point.

Note that point that is being returned as p. If p is equal to either u or v, then we have not found any point between x and y. Otherwise, u and v are not adjacent as p is between, so we will repeat this process for the pairs x and p and p and v.

Since every edge and every vertex of the polygon will use up a 1 query, then we need to use 2N queries to find all the points.

A few tips when implementing. We can work with integer coordinates all the time by mapping all (x, y) \to (2x, 2y). This way the midpoints will all have integer coordinates. Also, by repeating the process, we can think of it as divide-and-conquer on a polygon, so we can write it recursively or iteratively.


Comments

There are no comments at the moment.