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)
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
0)
1
2
10
Returns: 1.4142135623730951
maxVelocity is very large. So the train can keep speeding up until it reaches position 0.5.
1)
1
1
1
Returns: 2.0
2)
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.
3)
1
10
1
Returns: 1.1
4)
778
887
384
Returns: 2.458961621570838
5)
336
794
916
Returns: 1.301036207838119
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.