#P6848. Transforming a Polygon into an Equal‐Area Rectangle
Transforming a Polygon into an Equal‐Area Rectangle
Transforming a Polygon into an Equal‐Area Rectangle
You are given a simple polygon (S) defined by its vertices in counterclockwise order. The polygon (S) is described by an integer (n) ((n \ge 3)) and then (2\times n) numbers representing the coordinates ((x_0, y_0), (x_1, y_1), \ldots, (x_{n-1}, y_{n-1})). Your task is to produce any simple polygon (T) that has the same area as (S). In this problem, you are allowed to output a polygon with non‐integer coordinates even though the input coordinates are integers.
A convenient and valid solution is to transform (S) into a rectangle of area equal to that of (S). For example, you can output a rectangle with vertices ((0,0)), ((1,0)), ((1,A)), and ((0,A)), where (A) is the area of (S).
The area of a polygon (S) with vertices ((x_0, y_0), (x_1, y_1), \ldots, (x_{n-1}, y_{n-1})) is given by the formula (\text{Area}=\frac{1}{2}\left|\sum_{i=0}^{n-1}\left(x_i\times y_{(i+1) \bmod n}-y_i\times x_{(i+1) \bmod n}\right)\right|).
inputFormat
The first line of the input contains an integer (n) ((n \ge 3)) representing the number of vertices of polygon (S). The next (2\times n) numbers are the coordinates of the polygon, given in the order: (x_0, y_0, x_1, y_1, \ldots, x_{n-1}, y_{n-1}). The vertices are provided in counterclockwise order.
outputFormat
Output a polygon (T) that has the same area as (S) in the same format as the input polygon representation. That is, first output an integer (m) (the number of vertices of (T)), followed by (2\times m) numbers representing the coordinates of (T)'s vertices in counterclockwise order. A valid solution is to output the rectangle with vertices: ((0,0)), ((1,0)), ((1,A)), and ((0,A)), where (A) is the area of (S).
sample
3 0 0 1 0 0 1
4 0 0 1 0 1 0.5 0 0.5