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

Detour Buster

Detour Buster

The Green Parcel Services company employs cyclists to deliver parcels across a large metropolitan city, and employees are paid according to the distances they must travel to deliver parcels. Each company bicycle has been equipped with a global positioning system that records its position once every couple of seconds. The sequence of positions for one delivery is called a track and the length of a track, which is the sum of euclidean distances between consecutive pairs of recorded points, is used to calculate the employee's payment. A recent audit of the recorded tracks revealed that some tracks self-intersect, which indicates that some employees are making unnecessary detours. Your task is to write a program to process a given track and calculate the length of the shortest possible track from the first to the last point of the original track. The shortest possible track must be part of the original track and may include travelling in the same or opposite direction along the original track. \InputFile Input starts with an integer, on a line by itself, that represents the number of tracks tobe shortened. The description of each track begins with a positive integer \textbf{N}, on a line by itself, representing the number of recorded points that define the track. Each of the following \textbf{N} lines contains two integers, separated by a single space, that define the \textbf{x} and \textbf{y}-coordinates of a point on the track in metres. The points are listed in order of their appearance on the track. Two successive points, which form a segment, will be no more than thirty metres apart and a segment will not intersect more than twenty other segments. All \textbf{x}- and \textbf{y}-coordinates have values between \textbf{-10000000} and \textbf{10000000}, inclusive. \textbf{N} has values between \textbf{1} and \textbf{100000}, inclusive. \OutputFile For each input track, the output consists of a single integer, on a line by itself, which is the length of the shortest track in metres. The answer must be rounded to the nearest integer value. \textit{\textbf{Reminder}}: Rounding a positive number \textbf{R.xyz} to the nearest integer: \begin{itemize} \item If the first decimal place (that is \textbf{x}) is less than \textbf{5}, then the rounded value is \textbf{R}. \item Otherwise, the rounded value is \textbf{R+1}. \end{itemize}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
31
5
0 0
12 0
20 0
10 10
10 -10
6
0 0
15 0
10 -5
4 1
10 1
10 -10
Выходные данные #1
20
17
Источник The 2011 South Pacific Programming Contest