Two trains P90619


Statement
 

pdf   zip

html

Consider two infinite horizontal train rails, so close that we can regard them to be coincident. On the first rail there is a train of length ℓ1. To its right, on the second rail and d distance units apart, there is a train of length ℓ2. This simple picture corresponds to all the cases of the sample input, with ℓ1 = 10, ℓ2 = 20 and d = 30:

unit=0.2cm

(70,10) (10,06)10 (30,04)30 (55,06)20

linewidth=2pt linecolor=blue (05,04)(15,04) (45,04)(65,04)

linestyle=dotted linewidth=1pt linecolor=red <-(05,06)(09,06) ->(11,06)(15,06) <-(15,04)(29,04) ->(31,04)(45,04) <-(45,06)(54,06) ->(56,06)(65,06)

The first train has velocity v1 and constant acceleration a1. The second train has velocity v2 and constant acceleration a2. Positive means to the right, negative means to the left. For how many time units will the trains overlap, at least partially?

Input

Input consists of several cases, with only integer numbers, each one with ℓ1, ℓ2, d, v1, a1, v2 and a2. Assume that ℓ1, ℓ2 and d are strictly positive. No number is larger than 104 in absolute value.

Output

For every case, print with four digits after the decimal point the amount of time that both trains will overlap. The input cases have no precision issues.

Public test cases
  • Input

    10 20 30 10 0 20 0
    10 20 30 10 0 -10 5
    10 20 30 10 0 -10 1
    10 20 30 10 0 -10 -10
    

    Output

    0.0000
    4.0000
    3.4118
    0.8377
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++