Statistics

Problem Statement for "SubwayTrip"

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

  1. 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.

  2. 50

    5

    55

    20

    Returns: 0.005000000000000004

  3. 34

    3

    85

    7

    Returns: 0.028957528957528934

  4. 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.

  5. 60

    10

    100

    20

    Returns: 0.011904761904761906

  6. 60

    1

    10

    20

    Returns: 1.3661202185792296E-4

  7. 48

    4

    73

    15

    Returns: 0.007799145299145288

  8. 54

    9

    88

    6

    Returns: 0.03880070546737213

  9. 53

    10

    41

    12

    Returns: 0.010232604572227215

  10. 34

    7

    75

    3

    Returns: 0.1255380200860832

  11. 17

    10

    18

    3

    Returns: 0.13071895424836602

  12. 59

    9

    31

    2

    Returns: 0.034770687936191425

  13. 41

    1

    17

    18

    Returns: 5.484578655310384E-4

  14. 44

    5

    75

    3

    Returns: 0.05797773654916518

  15. 30

    6

    50

    5

    Returns: 0.055555555555555566

  16. 27

    3

    67

    12

    Returns: 0.020679012345679003

  17. 48

    1

    25

    7

    Returns: 0.001518464528668612

  18. 47

    8

    65

    10

    Returns: 0.02011605415860735

  19. 34

    1

    84

    15

    Returns: 0.0047058823529411795

  20. 10

    8

    73

    12

    Returns: 0.2703703703703704

  21. 10

    1

    97

    16

    Returns: 0.05511363636363638

  22. 32

    10

    68

    7

    Returns: 0.07227891156462586

  23. 10

    8

    72

    14

    Returns: 0.22857142857142862

  24. 54

    8

    31

    15

    Returns: 0.004938271604938271

  25. 34

    7

    60

    9

    Returns: 0.03347680535628885

  26. 13

    2

    45

    12

    Returns: 0.038461538461538484

  27. 12

    10

    56

    18

    Returns: 0.11784511784511784

  28. 52

    1

    62

    8

    Returns: 0.0028120464441219297

  29. 18

    4

    48

    12

    Returns: 0.04040404040404039

  30. 60

    8

    14

    14

    Returns: 0.00196078431372549

  31. 42

    8

    92

    6

    Returns: 0.05841269841269839

  32. 13

    10

    19

    7

    Returns: 0.09077878643096036

  33. 49

    5

    23

    11

    Returns: 0.003951075379646807

  34. 56

    6

    99

    10

    Returns: 0.01710829493087557

  35. 14

    8

    64

    18

    Returns: 0.09235209235209234

  36. 15

    10

    20

    4

    Returns: 0.13333333333333333

  37. 48

    6

    59

    20

    Returns: 0.006828703703703703

  38. 13

    9

    14

    16

    Returns: 0.02753496503496504

  39. 44

    9

    50

    14

    Returns: 0.013783386424895863

  40. 16

    10

    82

    12

    Returns: 0.1642628205128205

  41. 19

    6

    24

    15

    Returns: 0.020210526315789467

  42. 27

    1

    61

    14

    Returns: 0.0057634164777021915

  43. 22

    5

    72

    8

    Returns: 0.07575757575757579

  44. 14

    7

    21

    17

    Returns: 0.029411764705882353

  45. 50

    2

    46

    9

    Returns: 0.003931623931623929

  46. 38

    6

    13

    13

    Returns: 0.003588516746411481

  47. 60

    4

    44

    18

    Returns: 0.0025462962962962956

  48. 32

    8

    29

    19

    Returns: 0.009539473684210525

  49. 21

    7

    18

    9

    Returns: 0.023809523809523808

  50. 13

    5

    58

    15

    Returns: 0.08262108262108266

  51. 13

    9

    95

    20

    Returns: 0.14947552447552448

  52. 48

    9

    71

    19

    Returns: 0.012292243767313018

  53. 47

    2

    84

    2

    Returns: 0.03647416413373865

  54. 10

    8

    50

    2

    Returns: 1.0

  55. 25

    8

    73

    20

    Returns: 0.035393939393939394

  56. 34

    5

    48

    12

    Returns: 0.01508295625942685

  57. 24

    6

    59

    16

    Returns: 0.03072916666666666

  58. 31

    3

    58

    18

    Returns: 0.009171410499683742

  59. 56

    9

    44

    12

    Returns: 0.00906593406593406

  60. 42

    7

    100

    15

    Returns: 0.02267573696145125

  61. 54

    7

    33

    20

    Returns: 0.0035063752276866997

  62. 12

    7

    22

    4

    Returns: 0.16885964912280702

  63. 45

    4

    72

    3

    Returns: 0.043537414965986454

  64. 56

    1

    82

    4

    Returns: 0.006422305764411027

  65. 41

    2

    46

    2

    Returns: 0.02609188882586503

  66. 56

    4

    68

    12

    Returns: 0.006746031746031742

  67. 20

    10

    100

    2

    Returns: 0.8333333333333335

  68. 10

    1

    100

    2

    Returns: 0.4545454545454547

  69. 34

    3

    85

    16

    Returns: 0.01266891891891891

  70. 10

    10

    100

    20

    Returns: 0.25

  71. 10

    9

    100

    7

    Returns: 0.6766917293233083


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)2024, TopCoder, Inc. All rights reserved.
This problem was used for: