Under construction

Still being built. Things may change

Subway

Time limit1sMemory limit128 MB

Summary
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.

Examples4

  1. Example 1

    Input
    1000 70 20 1
    
    Expected output
    31.7
    
  2. Example 2

    Input
    10 5 2 1
    
    Expected output
    6.8
    
  3. Example 3

    Input
    500 50 10 3
    
    Expected output
    18.3
    
  4. Example 4

    Input
    1000 70 20 1
    2000 30 20 5
    1 10 10 10
    
    Expected output
    31.7
    71.6
    1.5