Two trains and two flies P64984


Statement
 

pdf   zip

thehtml

On the same rail there are two trains approaching each other. The train at the left goes to the right at constant speed t1. The train at the right goes to the left at constant speed t2. Initially, the noses of the trains are d distance units apart. There is a fly at the nose of the left train that starts flying to the right at constant speed f1, where f1 > t1. Similarly, there is a fly at the nose of the right train that starts flying to the left at constant speed f2, where f2 > t2. The flies are so small that we can consider them as points. Any time that a fly reaches another fly, or reaches a train, that fly turns around immediately, never changing the absolute value of its speed. Thus, the movement of each fly is like a zig-zag with an infinite number of rebounds.

Given all the information, can you compute the total distance travelled by each fly until the trains collide? If so, you would prove yourself even better than von Neumann!

Input

Input consists of several cases, each one with d, t1, t2, f1 and f2. All given numbers are strictly positive integers, and no larger than 106. Assume f1 > t1 and f2 > t2.

Output

For every case, print with four digits after the decimal point the total distance travelled by the first fly and by the second fly. The given cases have no precision issues.

Public test cases
  • Input

    1 1 1 2 2
    1234 12 23 42 100
    

    Output

    1.0000 1.0000
    1480.8000 3525.7143
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++