The Traveling Orienteerer
Time limit1sMemory limit256 MB
Given point coordinates and lists of courses, compute each course total Euclidean length rounded to the nearest integer.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Lasse is putting together the courses for an orienteering meet. A course is a list of control points visited in the given order, and Lasse needs one whose length is just right. He has no time to run every candidate himself, so Ola walks the forest with a GPS and records the coordinates of every control point. The lengths can now be computed from the coordinates alone.
The length of a course is the sum of the Euclidean distances between consecutive control points, in the order the course lists them. The distance between and is .
Given the coordinates of the control points and the list of courses, compute the total length of each course.
Input
The first line contains the number of control points (). Each of the next lines contains the coordinates and of one control point as floating-point numbers (). Control points are numbered to in the order they are given.
The next line contains the number of courses (). Each course takes two lines. The first line holds the number of control points on the course (), counting the start and the finish. The second line holds control point numbers in the order they are visited (). The same control point may appear several times on one course.
Output
For each course print its total length on its own line, rounded to an integer with no decimals. A fractional part of exactly rounds up. Process the courses in the order they are given.