Similar Polygons
Time limit1sMemory limit1024 MB
Decide whether two polygons are similar under rotation, reflection, translation, and scaling, then output the exact squared similarity ratio and the smallest matching vertex index.
- Level
Hard8 of 10
- Topics
- Geometry, String matching, Math, Implementation
- Solved
- No attempts yet
Problem
Two polygons are similar if all of their corresponding angles are equal and all of their corresponding side lengths are in the same ratio. Two similar polygons may be rotated, reflected (mirrored), and translated relative to each other. The ratio of the lengths of corresponding sides is called their similarity ratio.
Given two polygons, determine whether they are similar. If they are, report how their sizes relate and how their vertices correspond.
Input
The first line contains the number of vertices of each polygon ().
The second line contains the coordinates of the first polygon's vertices in order as integers: . Each coordinate is an integer between and .
The third line contains the second polygon's vertex coordinates in the same format.
The vertices of each polygon may be given in either clockwise or counterclockwise order. The given points always form a valid simple polygon with no two coincident vertices, no straight () interior angle, and no self-intersection.
Output
If the two polygons are not similar, print on a single line.
Otherwise, print two lines.
- On the first line, print the square of the similarity ratio (how many times larger the first polygon is than the second, squared — equivalently, the ratio of their areas) as an irreducible fraction , where and are positive integers with . This value is always rational, so it is written exactly; if the polygons are congruent it is .
- On the second line, print the smallest -based index of a vertex of the second polygon that can correspond to the first vertex of the first polygon under some valid similarity (rotation, reflection, translation, and uniform scaling). The vertices of each polygon are numbered from in input order.