TopcoderArchive
Archive
Algorithm problem

RunningWorkout

Problem statement, definition, constraints, and public examples.

Problem Statement

You are planning a running workout. It will consist of 3 laps at the local stadium. The length of each lap is L meters. You will run each lap at some constant speed, but your speed for different laps will be different. Specifically:
  • Your speed for the first lap will be v1 meters per second.
  • After finishing the first lap, you will immediately decrease your speed by v2 meters per second.
  • Then, after finishing the second lap, you will again decrease your speed immediately, this time by v3 meters per second.

Return the total time that your entire workout will take, in seconds.

Definition

Class:
RunningWorkout
Method:
getTime
Parameters:
int, int, int, int
Returns:
double
Method signature:
double getTime(int L, int v1, int v2, int v3)
(be sure your method is public)

Notes

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

Constraints

  • L will be between 100 and 1000, inclusive.
  • v2 and v3 will each be between 1 and 8, inclusive.
  • v1 will be between v2+v3+1 and 10, inclusive.

Examples

  1. 400
    8
    4
    3
    Returns: 550.0
    You are planning to run the first lap at 8 m/s, the second lap at 8-4 = 4 m/s and the last lap at 4-3 = 1 m/s. Therefore the laps will take you 400/8 = 50, 400/4 = 100 and 400/1 = 400 seconds. The total running time equals 50+100+400 = 550 seconds.
  2. 100
    10
    1
    1
    Returns: 33.611111111111114
  3. 1000
    3
    1
    1
    Returns: 1833.3333333333333
  4. 774
    7
    1
    5
    Returns: 1013.5714285714286
Back to all problems