Connection Status:
Competition Arena > ReturnToHome
SRM 318 · 2006-08-29 · by Andrew_Lazarev · Geometry
Class Name: ReturnToHome
Return Type: double
Method Name: goHome
Arg Types: (int, int, int, int)
Problem Statement

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.

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)
387
717
413
192
Returns: 384.0
76)
6
8
3
2
Returns: 7.0

Make three jumps and then walk the remaining 1 unit.

Submissions are judged against all 138 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ReturnToHome with a public method double goHome(int X, int Y, int D, int T) · 138 test cases · 2 s / 256 MB per case

Submitting as anonymous