Problem K
King's Keep

CC BY-SA 2.0 by David Dixon on geograph.co.uk, modified
King Carl’s kingdom contains $k$ keeps (commonly called castles).
Coordinates of keeps are known, and King Carl considers himself convinced that it could be convenient to choose a central keep as King Carl’s residence.
Critically, King Carl considers that the average cost to carry commands from King Carl’s residence to King Carl’s other keeps should be small.
Compute the minimal average Euclidean distance1 from his residence keep to the other keeps if King Carl chooses his residence optimally.
Input
The input consists of:
-
One line with an integer $k$ ($2\leq k\leq 1000$), the number of keeps.
-
$k$ lines, each with two integers $x$ and $y$ ($|x|, |y| \leq 1000$), the coordinates of the keeps.
It is guaranteed that all keeps are at distinct locations.
Output
Output the minimal possible average distance from the keep that is chosen as the king’s residence to all other keeps.
Your answer should have an absolute or relative error of at most $10^{-6}$.
Sample Input 1 | Sample Output 1 |
---|---|
3 0 0 9 9 0 9 |
9 |
Sample Input 2 | Sample Output 2 |
---|---|
5 -3 5 6 8 1 2 5 -4 -7 -9 |
8.405705684 |
Footnotes
- The Euclidean distance between two points is the length of a straight line segment between these points.