Connection Status:
Competition Arena > Subway2
SRM 413 · 2008-08-05 · by yuhch123 · Simple Math
Class Name: Subway2
Return Type: double
Method Name: minTime
Arg Types: (int, int, int)
Problem Statement

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.

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)
1
1
1
Returns: 2.0

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

Coding Area

Language: C++17 · define a public class Subway2 with a public method double minTime(int length, int maxAcceleration, int maxVelocity) · 67 test cases · 2 s / 256 MB per case

Submitting as anonymous