TopcoderArchiveVisit Topcoder
SRM5 Aug 2008
SRM 413

Subway2

Problem statement, definition, constraints, and public examples.

Problem Statement

Subway trains can move people quickly from one station to the next. It is known that the distance between two consecutive stations is length meters. For safety, the train can't move faster than maxVelocity meters/sec. For comfort, the absolute acceleration can't be larger than maxAcceleration meters/sec^2. The train starts with velocity 0 meters/sec, and it must stop at the next station (i.e., arrive there with a velocity of 0 meters/sec). Return the minimal possible time to get to the next station.

Definition

Class:
Subway2
Method:
minTime
Parameters:
int, int, int
Returns:
double
Method signature:
double minTime(int length, int maxAcceleration, int maxVelocity)
(be sure your method is public)

Notes

  • Your return value must be accurate to within an absolute or relative tolerance of 1E-9.
  • If the train's speed at time 0 is v0 and the acceleration is always a, then at time t the speed will be (v0 + t * a) and the train will be (v0 * t + 0.5 * a * t^2) away.

Constraints

  • length, maxAcceleration and maxVelocity will each be between 1 and 1000, inclusive.

Examples

  1. 1
    2
    10
    Returns: 1.4142135623730951
    maxVelocity is very large. So the train can keep speeding up until it reaches position 0.5.
  2. 1
    1
    1
    Returns: 2.0
  3. 10
    1
    1
    Returns: 11.0
    The train reaches its maximum velocity after 1 second, while traveling 0.5 meters. It then travels the next 9 meters in 9 seconds, and takes 1 second to decelerate to 0 m/s while covering the final 0.5 meters.
  4. 1
    10
    1
    Returns: 1.1
  5. 778
    887
    384
    Returns: 2.458961621570838
  6. 336
    794
    916
    Returns: 1.301036207838119
Back to all problems