TopCoder problem "SubwayTrip" used in TCHS09 Round 1 (Division I Level One)



Problem Statement

    You are walking down the escalator to catch a subway train. The escalator itself moves at a speed of Ve meters per minute. You can walk down the escalator at a relative speed of Vy meters per minute. The length of the escalator is L meters. Trains arrive T minutes apart.

Let t be the time between your arrival to the station if you stand still on the escalator and the arrival of the last train before your arrival. Assume that t is a random variable uniformly distributed between 0 and T.

Return the probability of catching an earlier train if you choose to walk down the escalator instead of standing still on it.
 

Definition

    
Class:SubwayTrip
Method:earlierTrain
Parameters:int, int, int, int
Returns:double
Method signature:double earlierTrain(int Ve, int Vy, int L, int T)
(be sure your method is public)
    
 

Notes

-The returned value must have an absolute or relative error less than 1e-9.
 

Constraints

-Ve will be between 10 and 60, inclusive.
-Vy will be between 1 and 10, inclusive.
-L will be between 10 and 100, inclusive.
-T will be between 2 and 20, inclusive.
 

Examples

0)
    
10
10
20
2
Returns: 0.5
If you stand still, it'll take you 20/10 = 2 minutes to reach the bottom of the escalator. If you choose to walk, it'll make you 20/(10+10) = 1 minute. In the second case you save 1 minute and in 50% of the cases it'll allow you to catch an earlier train.
1)
    
50
5
55
20
Returns: 0.005000000000000004
2)
    
34
3
85
7
Returns: 0.028957528957528934
3)
    
10
10
100
4
Returns: 1.0
Here, if you choose to walk instead of stand still, you will save 5 minutes and you will certainly be guaranteed to catch an earlier train.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13728&pm=10254

Writer:

Nickolas

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Math