Choose any point q in the plane and minimize the number of distinct Euclidean distances from q to n given integer points.
Hard8GeometryMathBrute forceCombinatoricsNo attempts yetTime limit3sMemory limit512 MBYou are setting up a scavenger hunt in the two-dimensional plane.
You have already chosen n distinct points of interest, labeled p1,p2,…,pn. Point pi sits at the integer coordinates (xi,yi).
Now you want to choose one more point q for the final location. The coordinates of q must be finite, but they do not have to be integers. Point q may coincide with one of the points pi.
To make the final location interesting, you want to minimize how many distinct distances there are from q to the chosen points. Formally, choose q that minimizes ∣S(q)∣, where
S(q)={∣q−p1∣, ∣q−p2∣, …, ∣q−pn∣}.
Here ∣S(q)∣ is the number of elements of S(q), and ∣q−pi∣ is the Euclidean distance between q and pi. S(q) is a set, so if two or more of the distances ∣q−pi∣ are equal, they count as a single element.
Given the coordinates of the points, find the minimum value of ∣S(q)∣.
Warning: inexact arithmetic may make it difficult to identify distances that are exactly equal.
The first line contains one integer n (1≤n≤40).
Each of the next n lines contains two space-separated integers xi and yi (∣xi∣,∣yi∣≤300), the coordinates of pi. The n points are pairwise distinct.
Print on a single line the minimum number of distinct distances from q to all of the points pi.
In the first sample you can take q=(0,0), and every point is at distance 5. In the second sample you can take q=(1.5,1.5).