Two trains

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 ℓ₁. To its right, on the second rail and d distance units apart,
there is a train of length ℓ₂. This simple picture corresponds to all
the cases of the sample input, with ℓ₁ = 10, ℓ₂ = 20 and d = 30:

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

(05,04)(15,04) (45,04)(65,04)

(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 v₁ and constant acceleration a₁. The second
train has velocity v₂ and constant acceleration a₂. 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 ℓ₁, ℓ₂, d, v₁, a₁, v₂ and a₂. Assume that ℓ₁, ℓ₂ and d are strictly
positive. No number is larger than 10⁴ 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.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:51:46.125Z

© Jutge.org, 2006–2026.
https://jutge.org
