Problem Statement

You are located at point (X, Y) and you want to get home to point (0, 0) as quickly as possible. There are two allowable methods of movement. The first method is walking, and you can walk at a speed of 1 unit per second. The second method is jumping, and you can jump D units in T seconds. You can jump in any straight direction, but you can only jump exactly D units. Return the minimum number of seconds required to get home using these two methods. You are not limited to using just one method for the entire trip; you can use any combination of walking and jumping.

Definition

 Class: ReturnToHome Method: goHome Parameters: int, int, int, int Returns: double Method signature: double goHome(int X, int Y, int D, int T) (be sure your method is public)

Notes

-Your return value must have an absolute or relative error less than 1e-9.

Constraints

-X will be between 1 and 1000, inclusive.
-Y will be between 1 and 1000, inclusive.
-D will be between 1 and 10000, inclusive.
-T will be between 1 and 10000, inclusive.

Examples

0)

 `6` `8` `5` `3`
`Returns: 6.0`
 The fastest way to get home is by using two jumps.
1)

 `3` `4` `6` `3`
`Returns: 4.0`
 You should jump one unit past your destination and then walk back.
2)

 `400` `300` `150` `10`
`Returns: 40.0`
 You should get home using four jumps.
3)

 `318` `445` `1200` `800`
`Returns: 546.9451526432975`
 The fastest way is to walk.
4)

 `6` `8` `3` `2`
`Returns: 7.0`
 Make three jumps and then walk the remaining 1 unit.
5)

 `10` `10` `1000` `5`
`Returns: 10.0`

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6684

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9998&pm=6684

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Cosmin.ro , Olexiy

Geometry