Dividing the Kingdom
Time limit2sMemory limit512 MB
Given n distinct integer-half points in the plane, output at most n-1 axis-parallel lines at integer coordinates so that no two points share a region.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Geometry, Sorting, Recursion
- Solved
- No attempts yet
Problem
The kingdom of Flatland is an infinite two-dimensional plane. The kingdom has castles. To make mapmaking easier, Flatland introduced a Cartesian coordinate system. Castle sits at the point with coordinates , where and are integers. All castle locations are pairwise distinct.
In his old age, the king decided to divide the kingdom on the map among his sons using lines parallel to the coordinate axes. If a line is parallel to the axis, then the coordinate of every point on it must be an integer; otherwise the coordinate of every point must be an integer. In both cases the absolute value of the relevant integer coordinate must not exceed . The king also wants any two castles to end up in different parts after the division.
Help the king divide the kingdom using at most lines. Any pair of lines must share at most one point.
Input
The first line contains the integer (), the number of castles in the kingdom. The next lines contain two numbers and (, ), the integer parts of the castle coordinates.
Output
On the first line, output the number of lines used. On the following lines, output the lines themselves, one per line. If a line is parallel to the axis, output the character y, then a space, then the coordinate of every point on that line. Otherwise output the character x, then a space, then the coordinate of every point on that line.
Hint
