Subway
Time limit1sMemory limit128 MB
Given distance, top speed, acceleration limit, and jerk limit, compute the minimum time to move a train between two stops.
- Level
Hard8 of 10
- Topics
- Math, Simulation, Implementation
- Solved
- No attempts yet
Problem
Subway trains are meant to move people as quickly, safely, and comfortably as possible from station to station. Although the train drivers' unions may not agree, computer-operated trains accomplish these goals more effectively than human-operated trains. Your task is to determine the optimal control strategy for moving the train from one station to another, subject to the constraints imposed by safety and comfort as well as the physical limitations of the train itself.
All parameters are positive integers not greater than 1000.
- d — the distance between the stations, in metres
- m — the maximum allowable speed of the train, in metres/second
- a — the maximum absolute acceleration of the train, in metres/second²
- j — the maximum absolute jerk of the train, in metres/second³
The train must be completely stopped at each station and must move in a single direction at speeds not exceeding m. Acceleration may be positive (forward) or negative (backward), but its absolute value must not exceed a. The last parameter, jerk, is the rate of change of acceleration in either direction; that is, acceleration may not increase or decrease faster than this rate. This constraint keeps standing passengers from being toppled.
Input
There are several test cases. Each test case is given on a single line containing d, m, a, and j, separated by spaces. Input continues until end of file.
Output
For each test case, print on a single line the minimum time in seconds, rounded to the nearest 0.1 second, required to travel between the stations.