Robot Challenge
InterviewTime limit1sMemory limit128 MB
The robot starts at (0,0), must visit targets in order, and may skip any target by paying its penalty. Find the minimum total time plus penalties to reach (100,100).
- Level
Medium6 of 10
- Topics
- Dynamic programming, Geometry, Shortest path, Greedy
- Solved
- No attempts yet
Problem
You have entered a robot in a Robot Challenge. A course is set up in a space. Certain points in the space are designated as targets, and they are ordered — there is a target 1, a target 2, and so on. Your robot must start at . From there it should go to target 1, stop for 1 second, go to target 2, stop for 1 second, and so on. It must finally reach, and stop for 1 second on, .
Every target except and has a time penalty for missing it. So if your robot went straight from target 1 to target 3, skipping target 2, it would incur target 2's penalty. Note that once it reaches target 3 it cannot go back to target 2; it must hit the targets in order. Because your robot stops for 1 second on each target point, it is in no danger of hitting a target accidentally too soon. For example, if target point 3 lies directly on the line between target points 1 and 2, your robot can go straight from 1 to 2, passing over 3 without stopping. Since it did not stop, the judges will not mistakenly think it hit target 3 too soon, so they will not assess target 2's penalty. Your final score is the time (in seconds) your robot takes to reach , completing the course, plus all penalties. Smaller scores are better.
Your robot is very maneuverable but a bit slow. It moves at but can turn very quickly. During the 1 second it stops on a target point, it can easily turn to face the next target point, so it can always move in a straight line between target points.
Because your robot is a bit slow, it may be advantageous to skip some targets and incur their penalty rather than actually maneuvering to them. Given a description of a course, determine your robot's best (lowest) possible score.
Input
The input contains several test cases. Each test case begins with a line containing one integer , the number of targets on the course. Each of the next lines describes a target with three integers , , and , where is a location on the course , in meters and is the penalty incurred if the robot misses that target . The targets are given in order — the first line after is target 1, the next is target 2, and so on. All targets on a given course are unique — there is at most one target point at any location on the course. The end of input is marked by a line containing a single .
Output
For each test case, output a single decimal number: the smallest possible score for that course. Output this number rounded (NOT truncated) to three decimal places. Print each answer on its own line, and do not print any blank lines between answers.