#C4027. Calculate Total Traveling Distance
Calculate Total Traveling Distance
Calculate Total Traveling Distance
You are given sensor data from a 2D plane. Each sensor provides a sequence of coordinates which indicate the positions it has visited. For each sensor, you must compute the total Euclidean distance traveled along these positions.
Given two consecutive points \( (x_1, y_1) \) and \( (x_2, y_2) \), the Euclidean distance between them is defined as:
\( d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} \)
The input consists of one or more groups. Each group starts with an integer indicating the number of sensors in that group. For each sensor, the first integer is the number of positions followed by that many lines each containing two integers for the coordinates. A group with the number of sensors equal to 0 indicates the end of input.
Output the total distance for each sensor (rounded to 4 decimal places) in the order they appear. After processing one group, print a line containing exactly "-----" (five hyphens) as a group separator.
inputFormat
The input is read from standard input and consists of multiple groups. Each group is structured as follows:
- The first line contains an integer \( S \) representing the number of sensors in this group. If \( S = 0 \), the input terminates.
- For each sensor, the first line contains an integer \( N \), the number of positions.
- Then follow \( N \) lines, each containing two space-separated integers representing the coordinates \( x \) and \( y \) of a position.
All input is provided via standard input (stdin).
outputFormat
For each sensor, output a line containing the total traveled distance rounded to 4 decimal places. After processing each group, output a line containing exactly "-----" (five hyphens) to separate groups. All output should be printed on standard output (stdout).
## sample2
3
0 0
3 4
6 8
4
1 1
2 2
3 3
4 4
2
2
0 0
0 4
3
1 1
1 2
1 3
0
10.0000
4.2426
4.0000
2.0000
</p>