eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Square

Given a square at \[\textbf{0}, \textbf{1}\]×\[\textbf{0}, \textbf{1}\] that has \textbf{N} points ( \textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N}) in the square (you may assume that different points can be at the same position), we can connect the \textbf{N} points and the four corners of the square with some line segments so that through these segments any two of the \textbf{N+4} points can reach each other (directly or indirectly). The \textit{graph length} is defined as the total length of the line segments. When \textbf{N} points’ positions are fixed, there must exist a way of connecting them, such that it will make the shortest graph length. We can use \textbf{LEN} (\textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N}) to record the graph length using this way of connecting. In this situation, \textbf{LEN} (\textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N}) is a function of \textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N}. When \textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N} change their positions, \textbf{LEN} (\textbf{P_1}, \textbf{P_2}, ..., \textbf{P_N}) also changes. It's easy to prove that there exist some \textbf{P_1'}, \textbf{P_2'}, ..., \textbf{P_N'} in the square such that \textbf{LEN} (\textbf{P_1'}, \textbf{P_2'}, ..., \textbf{P_N'}) is at its minimum. Given the initial positions of \textbf{N} points, your task is to find out \textbf{N} points \textbf{P_1''}, \textbf{P_2''}, ..., \textbf{P_N''} in the square such that |\textbf{P_1P_1''}| + |\textbf{P_2P_2''}| + ... + |\textbf{P_NP_N''}| is minimum and \textbf{LEN} (\textbf{P_1''}, \textbf{P_2''}, ..., \textbf{P_N''}) = \textbf{LEN} (\textbf{P_1'}, \textbf{P_2'}, ..., \textbf{P_N'}). You are requested to output the value of |\textbf{P_1P_1''}| + |\textbf{P_2P_2''}| + ... + |\textbf{P_NP_N''}|, where |\textbf{P_iP_i''}| is the distance between \textbf{P_i} and \textbf{P_iP_i''}. \includegraphics{https://static.e-olymp.com/content/79/79107099a281d238679dd1a5b84abf102262ea18.jpg} For example, Figure-1 gives the initial position of \textbf{P_1} and the way of connecting to obtain \textbf{LEN (P_1)}. In Figure-2, it gives the position of \textbf{P_1''}, which is at the center of the square, and the way of connecting to obtain \textbf{LEN (P_1'')}. It can be proved that \textbf{LEN (P_1'')} = \textbf{LEN (P_1')}; your job is to output the distance between \textbf{P_1} and \textbf{P_1''}. \InputFile The input consists of several test cases. For each test case, the first line consists of one integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}), the number of points, and \textbf{N} lines follow to give the coordinates for every point in the following format: \textbf{x y} Here, \textbf{x} and \textbf{y} are float numbers within the value \[\textbf{0}, \textbf{1}\]. A test case of \textbf{N = 0} indicates the end of input, and should not be processed. \OutputFile For each test case, output the value of |\textbf{P_1P_1''}| + |\textbf{P_2P_2''}| + ... + |\textbf{P_NP_N''}|. The value should be rounded to three digits after the decimal point.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
1
0.2 0.5
2
0 0.5
0.5 0.5
0
Выходные данные #1
0.300
0.500