#P8309. Magic Square Construction

    ID: 21488 Type: Default 1000ms 256MiB

Magic Square Construction

Magic Square Construction

Given four points in the Cartesian plane with coordinates ( (x_i, y_i) ) for ( i=1,2,3,4 ), use your magic to construct a square such that each given point lies on a different side’s supporting line of the square. More precisely, if the square has side length ( L ) and its sides lie on the lines ( x=X ), ( x=X+L ), ( y=Y ) and ( y=Y+L ) (i.e. an axis‐aligned square), then after an appropriate assignment of the four points to the four sides, one point must satisfy ( x=X ) (left side), one point must satisfy ( x=X+L ) (right side), one point must satisfy ( y=Y ) (bottom side) and one must satisfy ( y=Y+L ) (top side). If such a square exists, output its vertices in counter‐clockwise order starting from the bottom‐left vertex; otherwise, output -1.

Note: Although a square can be rotated arbitrarily, for this problem an axis–aligned square is sufficient to pass all test cases.

inputFormat

Input consists of four lines. Each line contains two numbers (integers or floats) representing the coordinates of a point:
( x_i ) and ( y_i ).

outputFormat

If there exists a square whose edges lie on lines ( x=X ), ( x=X+L ), ( y=Y ) and ( y=Y+L ) and such that each given point lies on a different one of these four lines, output eight numbers corresponding to the coordinates of the square’s four vertices in counter–clockwise order starting at the bottom–left vertex:
( X ) ( Y ), ( X+L ) ( Y ), ( X+L ) ( Y+L ), ( X ) ( Y+L ). Otherwise, output -1.

sample

0 1
3 2
2 3
1 0
0 0 3 0 3 3 0 3