Biometrics

Time limit1sMemory limit128 MB

Summary
Given two polygons with vertices in matching feature order, decide whether one maps onto the other by translation, rotation, and uniform scaling without reflection.
Level

Medium6 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Recently the term biometrics has been used to refer to the emerging field of technology devoted to identifying individuals using biological traits, such as retinal or iris scanning, fingerprints, or face recognition.

A simple biometric system turns a human image into a polygon: certain features (eyes, nose, ears, and so on) are treated as vertices and joined by line segments. The polygon's vertices are all distinct, but it may be degenerate in the sense that its segments can cross one another. Because such polygons are usually built from remote images, their scale and rotation are uncertain.

Your task is to decide whether two polygons are similar; that is, whether one can be made to coincide with the other using only translation, rotation, and uniform scaling (magnification). Reflection (mirroring) is not allowed.

Input

The input consists of several test cases. Each test case consists of:

  • ff, the number of features
  • ff coordinate pairs giving the vertices of the first polygon
  • ff coordinate pairs giving the vertices of the second polygon

The vertices of the two polygons correspond to the same set of features in the same order (for example: right ear tip, chin cleft, right eye, nose, left eye, left ear tip, gap between the front teeth). Each polygon has ff distinct vertices, and each vertex is given as an integer xx, yy coordinate pair. The number of features is at least 33 and at most 1010, and every coordinate is an integer between −1000-1000 and 10001000. A line containing a single 00 follows the last test case.

Output

For each test case, print similar or dissimilar on its own line. The two polygons are similar if, after some combination of translation, rotation, and scaling (but not reflection), every pair of vertices corresponding to the same feature ends up in the same position.

Examples4

  1. Example 1

    Input
    4
    0 0 0 1 1 1 1 0
    0 1 1 0 0 -1 -1 0
    3
    0 0 10 0 10 10
    0 0 -10 0 -10 10
    3
    0 0 10 10 20 20
    0 0 11 11 22 22
    3
    0 0 10 10 20 20
    0 0 11 11 20 20
    0
    
    Expected output
    similar
    dissimilar
    similar
    dissimilar
    
  2. Example 2

    Input
    3
    0 0 1 0 0 1
    5 5 5 7 3 5
    0
    
    Expected output
    similar
    
  3. Example 3

    Input
    3
    0 0 1 0 0 1
    0 0 1 0 0 -1
    0
    
    Expected output
    dissimilar
    
  4. Example 4

    Input
    3
    0 0 3 4 -2 7
    0 0 3 4 -2 7
    4
    0 0 2 0 2 3 0 3
    100 -50 102 -50 102 -47 100 -47
    0
    
    Expected output
    similar
    similar