eolymp
bolt
Try our new interface for solving problems
Problems

Interior Points of Lattice Polygons

Interior Points of Lattice Polygons

A \textbf{lattice point} is a point with \textbf{integer} coordinates. A \textbf{lattice polygon} is a polygon with all vertices lattice points. \includegraphics{https://static.e-olymp.com/content/32/321d268929319ac596de9f0a0cf7af440818e8ae.jpg} The lattice points on the boundary of the polygon are \textbf{boundary points} (open dots in the figure above) and the points inside and not on the polygon are \textbf{interior points} (filled in dots in the figure above). A polygon is convex if any line segment between two points of the polygon is inside (or on the boundary of) the polygon. Equivalently, the interior angle at each polygon vertex is less than \textbf{180} degrees. Note that any line between two points inside (and not on the boundary of) the polygon is entirely inside (and not on the boundary of) the polygon. The interior points of a convex lattice polygon on any horizontal line form a single segment from a leftmost point to a rightmost point (which may be the same). Note that there may be no interior points (A), or only one (B), or isolated points (C) as shown in the figures below. \includegraphics{https://static.e-olymp.com/content/6f/6ff95dd4082d6f8378679f6cf93dd9a9705e08ce.jpg} Write a program that reads the vertices of a convex lattice polygon in standard order and outputs the interior points as a list of horizontal line segments. The vertices of a lattice polygon are in standard order if: a) The first vertex is the one with the largest \textbf{y} value. If two vertices have the same y value, the one with the smaller \textbf{x} value is the first. b) Vertices are given in clockwise order around the polygon. \InputFile The first line of input contains a single integer \textbf{P}, (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000}), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by a decimal integer giving the number vertices \textbf{N}, (\textbf{3} ≤ \textbf{N} ≤ \textbf{50}), of the polygon. The remaining lines in the data set contain the vertices, one per line in standard order. Each line contains the decimal integer x coordinate, a space and the decimal integer y coordinate. \OutputFile For each data set there are multiple lines of output. The first line contains a decimal integer giving the data set number followed by a single space, followed by a decimal integer giving the number of horizontal lines which contain interior points (this may be zero (\textbf{0}) or more). The lines of interior points, if any, follow, one per line in order of decreasing \textbf{y} value. Each line contains the decimal integer \textbf{y} coordinate, a single space and the decimal integer \textbf{x} coordinate of the left most point, a single space and the decimal integer \textbf{x} coordinate of the right most point.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
1 8
5 10
8 9
11 6
10 2
6 0
1 1
0 4
2 8
Output example #1
1 9
9 4 7
8 3 8
7 2 9
6 2 10
5 1 10
4 1 10
3 1 10
2 1 9
1 2 7