TopcoderArchiveVisit Topcoder
SRM29 Aug 2006
SRM 318

ReturnToHome

Problem statement, definition, constraints, and public examples.

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

  1. 6
    8
    5
    3
    Returns: 6.0
    The fastest way to get home is by using two jumps.
  2. 3
    4
    6
    3
    Returns: 4.0
    You should jump one unit past your destination and then walk back.
  3. 400
    300
    150
    10
    Returns: 40.0
    You should get home using four jumps.
  4. 318
    445
    1200
    800
    Returns: 546.9451526432975
    The fastest way is to walk.
  5. 6
    8
    3
    2
    Returns: 7.0
    Make three jumps and then walk the remaining 1 unit.
  6. 10
    10
    1000
    5
    Returns: 10.0
Back to all problems