Supply Mission
Time limit2sMemory limit128 MB
Find the minimum total time for a helicopter to visit every moving submarine in any order, land one hour at each, and return to base.
- Level
Hard8 of 10
- Topics
- Brute force, Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
You must pilot a helicopter to deliver supplies to several submarines moving across the ocean.
You are given the coordinates of the helicopter base and of each submarine. Submarine moves at the constant velocity given by the vector : after one hour it has moved km along the x-axis and km along the y-axis ( and may be negative). The length of this vector is the submarine's speed.
The helicopter moves at a constant speed in any direction (assume that acceleration and deceleration are instantaneous). It must land on each submarine at least once, and every stop takes exactly one hour to unload supplies and refuel. A submarine surfaces at its scheduled landing time and submerges again once the helicopter leaves; a submarine's velocity is never affected by its depth. While the helicopter waits during that one-hour stop it stays on the submarine, so it moves together with the submarine at the submarine's constant velocity. The helicopter can carry enough supplies for every submarine at once, so it never has to go back to the base during the mission.
All coordinates are in km and all speeds are in km/h.
Find the shortest possible time for the helicopter to start at the base, deliver supplies to every submarine, and return to the base.
Input
The input contains several test cases.
Each test case begins with a line containing an integer (), the number of submarines. Each of the next lines contains four integers separated by spaces: the initial coordinates and of that submarine followed by its velocity components and . The final line of the test case contains three integers: the and coordinates of the helicopter base and the helicopter's speed.
The input ends with a test case whose first line is ; do not process that case.
Every integer in the input has absolute value at most . The helicopter is always strictly faster than every submarine. The paths of the submarines may cross one another or even pass through the base, but because they can change depth there are never any collisions.
Output
For each test case, print its case number followed by the minimum time required to complete the mission, in the format:
Case a: b hour(s) c minute(s) d second(s)
where , , , and are non-negative integers and and are at most . Round the time up to the next whole second.