#P3217. Global Tour Rectangle
Global Tour Rectangle
Global Tour Rectangle
A famous singer is planning his global tour and has marked his favorite cities as points on a plane. He wants to choose exactly 4 cities such that they are the 4 vertices of a rectangle. Moreover, he insists that the area of this rectangle is maximized.
Your task is to help him by selecting 4 points from the given list that form the vertices of a rectangle with the maximum possible area. If no rectangle can be formed, output 0.
Recall that for a rectangle with two adjacent sides of lengths l and w, its area is given by \[ A = l \times w \] For a given vertex A and two other points B and C, if \((B-A)\) and \((C-A)\) are perpendicular (i.e. their dot product is 0), then the fourth vertex D is given by \[ D = B + C - A \] and the area of the rectangle is \[ A = |AB| \times |AC| \] where \(|AB|\) is the Euclidean distance between points A and B, and similarly for \(|AC|\).
inputFormat
The first line contains an integer n
representing the number of points.
Each of the following n
lines contains two space‐separated integers x
and y
, representing the coordinates of a point.
You may assume that all points are distinct.
outputFormat
Output a single number, which is the maximum area of the rectangle that can be formed by any 4 points from the input. If no rectangle exists, output 0.
The answer will be considered correct if it has an absolute or relative error of at most 10-6.
sample
4
0 0
0 1
1 0
1 1
1.0