Similar Polygons
Time limit1sMemory limit1024 MB
Decide whether two polygons are similar, and if so print the square of the similarity factor as a reduced fraction and the matching vertex index in the second polygon.
- Level
Hard8 of 10
- Topics
- Geometry, String matching, Implementation, Math
- Solved
- No attempts yet
Problem
Juku is learning about polygon similarity at school. Two polygons are similar if all corresponding angles are equal and all corresponding side lengths are in the same ratio. Similar polygons may be rotated, reflected, and translated relative to one another. The ratio of corresponding side lengths of two similar polygons is called their similarity factor.
For homework Juku receives several pairs of polygons and must decide, for each pair, whether the polygons are similar and, if so, what their similarity factor is. Some polygons have a very large number of vertices, so help Juku finish his homework.
Input
The first line contains the number of polygon vertices (). The second line contains integers between and : the and coordinates of the vertices of the first polygon, in order. The third line likewise contains the coordinates of the second polygon's vertices.
The vertices may be given in either clockwise or counterclockwise order. The given points always form a polygon with no coinciding points, no straight () angles, and no self-intersections. Moreover, within each polygon all side lengths are distinct.
Output
If the two polygons are similar, print two lines.
- On the first line print the square of the enlargement factor as a reduced fraction
p/q. The enlargement factor is how many times larger the first polygon is than the second (if the first is smaller, it is less than ); and are positive integers with , and the denominator is always written, even when it is (e.g.2/1). The factor itself may be irrational and thus cannot be compared exactly, so its square — which is always rational — is printed instead (the factor is ). - On the second line print the index of the vertex of the second polygon that corresponds to the first vertex of the first polygon. Vertices of both polygons are numbered from in the order they appear in the input.
If the polygons are not similar, print on a single line.
Because all side lengths within a polygon are distinct (so the polygon has no symmetry), this correspondence is uniquely determined.