Statistics

Problem Statement for "ScrabbleBet"

Problem Statement

One Saturday evening you are playing a game of online Scrabble. Your opponent is a very good player, but this time you managed to win. After a brief conversation, you are told: "I am clearly better than you, but one game is simply not enough to prove it." Your opponent then makess the following bet: "If we play 10 games, you will win less than 5 ... and this will happen every time, even if we try this 10 times in a row!".

You will solve a more general problem using the following parameters:
- an int trials denoting the number of meetings in which a set of games is played.
- an int games denoting the number of games that are to be played in each meeting.
- an int winsNeeded denoting the number of victories you need in one of the meetings to win the bet.
- an int winChance denoting the probability in percent of winning one particular game.

Return a double between 0 and 1, denoting the probability you have to win the bet.

Definition

Class:
ScrabbleBet
Method:
estimate
Parameters:
int, int, int, int
Returns:
double
Method signature:
double estimate(int trials, int games, int winsNeeded, int winChance)
(be sure your method is public)

Notes

  • Your return value must have an absolute or relative error less than 1e-9.

Constraints

  • trials will be between 1 and 50, inclusive.
  • games will be between 1 and 20, inclusive.
  • winsNeeded will be between 1 and games, inclusive.
  • winChance will be between 0 and 100, inclusive.

Examples

  1. 2

    2

    1

    50

    Returns: 0.9375

    There are 4 possible ways a meeting could evolve: - you lose both games. - you lose game 1 and you win game 2. - you win game 1 and you lose game 2. - you win both games. Your opponent has a 1/4 chance of not losing the bet after the first meeting. Since there are two meetings, your opponent's chances to win the bet are 1/4 * 1/4 = 1/16. Thus, you have a 15/16 chance to win the bet.

  2. 2

    2

    2

    50

    Returns: 0.4375

    This time your opponent has a 3/4 chance of not losing the bet after one meeting and a 9/16 chance of not losing the bet after the two meetings. Your chances are now 1 - 9/16 = 7/16.

  3. 10

    10

    5

    25

    Returns: 0.5566860567603682

  4. 2

    20

    5

    10

    Returns: 0.08448495352665641

  5. 50

    15

    1

    0

    Returns: 0.0

  6. 50

    17

    16

    100

    Returns: 1.0

  7. 50

    10

    10

    75

    Returns: 0.9448701546682944

  8. 50

    1

    1

    1

    Returns: 0.39499393286246354

  9. 50

    2

    2

    1

    Returns: 0.004987769576990653

  10. 50

    20

    20

    81

    Returns: 0.5250569771959787

  11. 50

    20

    10

    3

    Returns: 4.138295262023917E-9

  12. 1

    20

    18

    90

    Returns: 0.676926805189466

  13. 40

    15

    7

    45

    Returns: 0.9999999999999837

  14. 16

    13

    13

    4

    Returns: 0.0

  15. 44

    15

    5

    11

    Returns: 0.565146716273372

  16. 33

    5

    5

    1

    Returns: 3.3000002730432243E-9

  17. 16

    13

    8

    1

    Returns: 1.9699797348948778E-12

  18. 49

    10

    10

    14

    Returns: 1.4173477047574323E-7

  19. 49

    14

    11

    58

    Returns: 0.9929135760091945

  20. 18

    7

    5

    69

    Returns: 0.9999999777416546

  21. 27

    9

    9

    8

    Returns: 3.6238791967235784E-9

  22. 18

    5

    3

    43

    Returns: 0.9997587412531408

  23. 40

    1

    1

    1

    Returns: 0.3310282414303197

  24. 29

    7

    3

    34

    Returns: 0.9999999610106829

  25. 3

    18

    5

    4

    Returns: 0.0016975880254400666

  26. 1

    11

    6

    26

    Returns: 0.04118903683622188

  27. 23

    5

    1

    57

    Returns: 1.0

  28. 49

    19

    15

    22

    Returns: 1.0336054480419854E-5

  29. 33

    13

    10

    12

    Returns: 4.133856688515181E-6

  30. 2

    13

    10

    74

    Returns: 0.7981605453468209

  31. 50

    11

    8

    5

    Returns: 2.8120113459984E-7

  32. 18

    4

    3

    81

    Returns: 0.9999999999999912

  33. 24

    11

    5

    9

    Returns: 0.04033011176814705

  34. 50

    20

    11

    41

    Returns: 0.999667822769

  35. 33

    9

    9

    22

    Returns: 3.9839114637896245E-5

  36. 50

    18

    3

    72

    Returns: 1.0

  37. 49

    9

    8

    54

    Returns: 0.814876016676038

  38. 6

    18

    3

    11

    Returns: 0.8987322831202943

  39. 50

    19

    18

    98

    Returns: 1.0

  40. 47

    19

    18

    34

    Returns: 2.231689414378124E-6

  41. 50

    12

    8

    5

    Returns: 8.061755853994157E-7

  42. 22

    18

    4

    12

    Returns: 0.9794115810094438

  43. 35

    2

    2

    0

    Returns: 0.0

  44. 25

    15

    5

    14

    Returns: 0.7064508968154499

  45. 34

    20

    17

    1

    Returns: 0.0

  46. 8

    2

    1

    65

    Returns: 0.9999999492905722

  47. 50

    8

    1

    99

    Returns: 1.0

  48. 49

    8

    3

    21

    Returns: 0.9999963518258111

  49. 14

    7

    5

    11

    Returns: 0.003900675571786638

  50. 4

    8

    4

    58

    Returns: 0.9981934313486637

  51. 10

    9

    4

    9

    Returns: 0.055598874821344624

  52. 38

    19

    2

    1

    Returns: 0.4428278729962877

  53. 49

    13

    1

    0

    Returns: 0.0

  54. 5

    4

    4

    30

    Returns: 0.03984919292150724

  55. 50

    18

    17

    24

    Returns: 2.0239526721255174E-8

  56. 50

    8

    5

    9

    Returns: 0.013009428767352116

  57. 27

    14

    6

    93

    Returns: 1.0

  58. 37

    10

    2

    55

    Returns: 1.0

  59. 49

    13

    12

    50

    Returns: 0.08039575630037099

  60. 32

    8

    1

    100

    Returns: 1.0

  61. 18

    4

    3

    12

    Returns: 0.10736376079946097

  62. 40

    5

    4

    10

    Returns: 0.018235909601249878

  63. 38

    6

    6

    49

    Returns: 0.4111848009007051

  64. 14

    9

    2

    88

    Returns: 1.0

  65. 49

    16

    3

    27

    Returns: 1.0

  66. 10

    5

    2

    74

    Returns: 1.0

  67. 49

    2

    2

    2

    Returns: 0.019413013731441886

  68. 50

    4

    2

    12

    Returns: 0.9776464635292131

  69. 2

    13

    10

    42

    Returns: 0.02317069244188419

  70. 50

    19

    12

    55

    Returns: 0.9999999947108317

  71. 50

    7

    6

    66

    Returns: 0.9999994796213061

  72. 13

    10

    2

    100

    Returns: 1.0

  73. 50

    10

    9

    13

    Returns: 4.681875731993301E-6

  74. 3

    4

    2

    45

    Returns: 0.9402321281438738

  75. 1

    17

    13

    22

    Returns: 2.703945773396832E-6

  76. 2

    7

    5

    11

    Returns: 5.581731702325454E-4

  77. 50

    20

    10

    23

    Returns: 0.3152314209871049

  78. 50

    20

    15

    99

    Returns: 1.0

  79. 49

    19

    10

    78

    Returns: 1.0

  80. 49

    19

    11

    43

    Returns: 0.9993955411352937

  81. 5

    20

    10

    42

    Returns: 0.8395138357738366

  82. 50

    20

    13

    13

    Returns: 4.780366629431043E-6

  83. 50

    10

    10

    75

    Returns: 0.9448701546682944

  84. 48

    17

    11

    45

    Returns: 0.9840391872684441

  85. 50

    20

    15

    69

    Returns: 0.9999999999538539

  86. 50

    20

    13

    43

    Returns: 0.8678241798679364

  87. 1

    20

    10

    50

    Returns: 0.5880985260009766

  88. 50

    20

    19

    72

    Returns: 0.4615168664126693

  89. 10

    10

    5

    25

    Returns: 0.5566860567603682

  90. 2

    2

    1

    50

    Returns: 0.9375

  91. 2

    20

    5

    10

    Returns: 0.08448495352665641

  92. 50

    17

    16

    100

    Returns: 1.0

  93. 50

    20

    10

    23

    Returns: 0.3152314209871049

  94. 50

    20

    15

    99

    Returns: 1.0

  95. 49

    19

    10

    78

    Returns: 1.0

  96. 49

    19

    11

    43

    Returns: 0.9993955411352937

  97. 5

    20

    10

    42

    Returns: 0.8395138357738366

  98. 50

    20

    13

    13

    Returns: 4.780366629431043E-6

  99. 50

    10

    10

    75

    Returns: 0.9448701546682944

  100. 48

    17

    11

    45

    Returns: 0.9840391872684441

  101. 50

    20

    15

    69

    Returns: 0.9999999999538539

  102. 50

    20

    13

    43

    Returns: 0.8678241798679364

  103. 1

    20

    10

    50

    Returns: 0.5880985260009766

  104. 50

    20

    19

    72

    Returns: 0.4615168664126693

  105. 10

    10

    5

    25

    Returns: 0.5566860567603682

  106. 2

    2

    1

    50

    Returns: 0.9375

  107. 2

    20

    5

    10

    Returns: 0.08448495352665641

  108. 50

    17

    16

    100

    Returns: 1.0


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: