TopCoder problem "Subway2" used in SRM 413 (Division II Level One)



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

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9840

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13504&pm=9840

Writer:

yuhch123

Testers:

PabloGilberto , legakis , Olexiy , ivan_metelsky

Problem categories:

Simple Math