#P7459. Reservoir Dog

    ID: 20654 Type: Default 1000ms 256MiB

Reservoir Dog

Reservoir Dog

You bring your dog to play at a reservoir near your house. Your dog loves playing frisbee but you have grown tired of playing fetch. Thus, you are curious about the total elapsed time between when you throw the frisbee and when your dog picks it up and brings it back to you.

At time \(T_f\) milliseconds, you throw the frisbee horizontally from a height of \(H_f\) millimeters with an initial horizontal speed \(V_f\) (in mm/ms). Gravity causes a constant downward acceleration of \(1\) mm/(ms²) for the frisbee. Thus, for \(t\ge T_f\), the frisbee’s position is given by:

[ x_f(t) = V_f (t-T_f), \quad y_f(t) = H_f - 0.5 (t-T_f)^2. ]

At time \(T_d\) milliseconds you release your dog. The dog, capable of instantaneously reaching any horizontal speed (up to a maximum of \(V_d\) mm/ms) and of changing direction even while airborne, runs on an ideal flat plane. However, when it leaps the dog can only jump to a maximum vertical height of \(H_d\) millimeters. In its jump the dog is affected by gravity with a downward acceleration of \(3\) mm/(ms²) (its vertical motion, like the frisbee’s, obeys the displacement formula \(s(t) = s_0+v_0t+0.5at^2\)). Jumping does not affect the dog’s horizontal speed.

The clever dog will plan an optimal path in order to catch the frisbee as soon as possible and then immediately dash back to your position at maximum speed \(V_d\). The time measurement stops the moment the dog, even if still airborne, passes directly above your starting position (i.e. the horizontal coordinate 0).

Under the assumption that both the frisbee and the dog may be considered as point objects, determine the total elapsed time from when the frisbee is thrown (at \(T_f\)) until the dog returns to you. Note that the dog is released at \(T_d\), and it may wait until it is physically possible to intercept the frisbee. In order for the dog to intercept the frisbee, it must meet the following conditions at some catch time \(t_c\):

  • \(t_c \ge T_f\) and \(t_c \ge T_d\).
  • The frisbee must have fallen to a height that the dog can reach. That is, \(y_f(t_c)=H_f-0.5(t_c-T_f)^2 \le H_d\). Equivalently, if \(H_f > H_d\) then \(t_c \ge T_f+\sqrt{2(H_f-H_d)}\); otherwise, this condition is automatically satisfied.
  • The dog must be able to cover the horizontal distance to intercept the frisbee. When the frisbee is caught at \(x_f(t_c)=V_f(t_c-T_f)\), the dog (released at time \(T_d\)) can have covered at most \(V_d(t_c-T_d)\) distance. Hence, the condition is \(V_f(t_c-T_f) \le V_d(t_c-T_d)\). This condition can be rewritten as follows:
    • If \(V_d>V_f\): then \(t_c \ge \frac{V_dT_d-V_fT_f}{V_d-V_f}\).
    • If \(V_d<V_f\): then \(t_c \le \frac{V_fT_f-V_dT_d}{V_f-V_d}\) (and a solution exists only if the lower time bounds do not exceed this upper bound).

Once the dog catches the frisbee at time \(t_c\), it immediately runs back to you. The returning time is the horizontal distance \(V_f(t_c-T_f)\) divided by the speed \(V_d\). Therefore, the total elapsed time (measured from \(T_f\)) is:

[ \text{Total time} = (t_c-T_f)+\frac{V_f(t_c-T_f)}{V_d} = (t_c-T_f)\left(1+\frac{V_f}{V_d}\right). ]

Your task is to compute this minimal total time given the parameters.

inputFormat

The input consists of six space-separated numbers:

  1. \(T_f\): the time (in milliseconds) when the frisbee is thrown.
  2. \(H_f\): the height (in millimeters) from which the frisbee is thrown.
  3. \(V_f\): the initial horizontal speed (in mm/ms) of the frisbee.
  4. \(T_d\): the time (in milliseconds) when the dog is released.
  5. \(V_d\): the maximum horizontal speed (in mm/ms) of the dog.
  6. \(H_d\): the maximum vertical jump height (in millimeters) of the dog.

You may assume that all input values are non-negative real numbers. It is guaranteed that a solution exists.

outputFormat

Output the minimal total elapsed time (in milliseconds) from when the frisbee is thrown until the dog returns to your position. The answer will be accepted if it is correct within a relative or absolute error of \(10^{-6}\).

sample

0 1000 10 0 20 500
47.433000