Statistics

Problem Statement for "DiceThrows"

Problem Statement

The players A and B are playing a game with dice. Player A throws numDiceA of his dice, while player B throws numDiceB of his dice. Each of them adds the pips on his dice, and the player with the higher sum wins the game (if both get the same sum, it is a draw). The variables sidesA and sidesB have 6 elements each, and describe how many pips are on each side of the dice of player A and player B respectively. Each die has exactly 1/6 probability for each possible outcome.

Given the number of dice numDiceA and numDiceB each player throws, and their configurations sidesA and sidesB, compute the probability that player A wins the game.

Definition

Class:
DiceThrows
Method:
winProbability
Parameters:
int, int[], int, int[]
Returns:
double
Method signature:
double winProbability(int numDiceA, int[] sidesA, int numDiceB, int[] sidesB)
(be sure your method is public)

Notes

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

Constraints

  • numDiceA and numDiceB are between 1 and 200, inclusive.
  • sidesA and sidesB each contain exactly 6 elements.
  • Each element of sidesA and sidesB is between 1 and 100, inclusive.

Examples

  1. 1

    {1,2,3,4,5,6}

    1

    {1,2,3,4,5,6}

    Returns: 0.41666666666666663

    This is the simple case, where each player throws a normal die once. Of the 36 possible outcomes, 6 are a tie (both players throw the same number), 15 a win for A and 15 a win for B. So player A wins 15/36 of the games.

  2. 200

    {1,3,8,18,45,100}

    200

    {1,4,10,21,53,100}

    Returns: 0.25240407058279035

  3. 2

    {1,1,1,2,2,2}

    3

    {1,1,1,1,1,1}

    Returns: 0.25

    Note that dice can have several equal sides. Here, player B gets a sum of 3. Player A can beat that only if he gets a 2 on both his throws, giving him a 1/4 chance of winning.

  4. 200

    {6,5,4,3,2,1}

    200

    {3,4,6,5,1,2}

    Returns: 0.49416239842107595

    Note that sidesA and sidesB need not be sorted.

  5. 100

    {1,1,1,1,1,2}

    199

    {1,1,1,1,1,1}

    Returns: 1.5306467074865068E-78

    There is a 6-100 probability of player A winning (all his throws are 2).

  6. 1

    {1,2,1,2,1,2}

    1

    {2,1,2,1,2,1}

    Returns: 0.25

  7. 200

    {1,3,8,18,45,100}

    80

    {1,4,10,21,53,100}

    Returns: 0.9999999976160046

  8. 100

    {1,3,5,10,15,20}

    100

    {9,9,9,9,9,9}

    Returns: 0.4943375131579816

  9. 100

    {7,8,9,9,10,11}

    100

    {1,3,5,10,15,20}

    Returns: 0.49968090996086173

  10. 10

    {1,2,3,4,5,6}

    1

    {59,70,80,90,95,100}

    Returns: 2.7563619479867007E-9

  11. 1

    {60,70,80,90,95,100}

    10

    {1,2,3,4,5,6}

    Returns: 0.9999999972436379

  12. 91

    {69, 98, 52, 53, 48, 89}

    133

    {51, 9, 99, 12, 44, 43}

    Returns: 0.8922893426623625

  13. 131

    {3, 72, 90, 25, 91, 34}

    175

    {18, 45, 63, 27, 51, 36}

    Returns: 0.38895365380512525

  14. 137

    {60, 28, 29, 5, 14, 19}

    92

    {45, 100, 16, 32, 51, 11}

    Returns: 0.142456572809483

  15. 155

    {99, 39, 55, 85, 21, 52}

    153

    {95, 67, 66, 5, 84, 41}

    Returns: 0.4480478450853752

  16. 196

    {71, 41, 29, 76, 96, 12}

    189

    {77, 9, 47, 95, 72, 44}

    Returns: 0.34670932289383705

  17. 74

    {82, 57, 69, 2, 77, 75}

    107

    {68, 83, 6, 31, 42, 3}

    Returns: 0.7895416899310314

  18. 195

    {94, 40, 1, 8, 81, 11}

    142

    {24, 39, 74, 17, 76, 88}

    Returns: 0.5714253512162418

  19. 101

    {17, 82, 37, 97, 59, 23}

    114

    {73, 79, 80, 31, 6, 34}

    Returns: 0.14213780140021903

  20. 167

    {14, 49, 45, 79, 55, 90}

    184

    {42, 71, 60, 47, 32, 23}

    Returns: 0.9815760232124386

  21. 103

    {57, 88, 39, 21, 19, 91}

    128

    {29, 54, 88, 32, 82, 5}

    Returns: 0.04037445470659537

  22. 61

    {87, 87, 75, 41, 42, 58}

    62

    {89, 78, 47, 63, 87, 23}

    Returns: 0.4404035701658416

  23. 63

    {75, 27, 98, 92, 65, 48}

    126

    {72, 56, 1, 62, 16, 31}

    Returns: 0.01593491572116412

  24. 118

    {65, 52, 4, 73, 90, 65}

    184

    {50, 3, 16, 67, 37, 82}

    Returns: 0.020732525118590778

  25. 33

    {14, 32, 91, 97, 48, 28}

    39

    {80, 50, 11, 38, 96, 13}

    Returns: 0.2665639976189537

  26. 59

    {75, 21, 78, 64, 9, 82}

    73

    {80, 97, 40, 20, 51, 18}

    Returns: 0.07091673648667753

  27. 82

    {39, 74, 28, 24, 75, 22}

    57

    {33, 64, 79, 40, 39, 92}

    Returns: 0.8592708622541287

  28. 54

    {63, 87, 6, 9, 62, 100}

    75

    {54, 12, 13, 95, 8, 42}

    Returns: 0.6503180290720642

  29. 98

    {36, 69, 78, 48, 95, 89}

    168

    {6, 28, 29, 29, 60, 84}

    Returns: 0.669735268455362

  30. 176

    {56, 86, 13, 17, 99, 58}

    111

    {89, 78, 63, 99, 95, 63}

    Returns: 0.9226976824449573

  31. 165

    {48, 99, 56, 89, 37, 29}

    191

    {61, 16, 58, 97, 10, 84}

    Returns: 0.16818711679580858

  32. 13

    {46, 83, 42, 21, 31, 47}

    10

    {51, 17, 22, 85, 43, 73}

    Returns: 0.8280454034647005

  33. 78

    {42, 15, 86, 71, 17, 2}

    43

    {97, 40, 99, 68, 5, 23}

    Returns: 0.9656249263567392

  34. 137

    {36, 61, 48, 31, 96, 85}

    100

    {94, 75, 88, 30, 88, 69}

    Returns: 0.9840863679633509

  35. 127

    {21, 22, 54, 64, 72, 94}

    185

    {13, 5, 100, 53, 23, 45}

    Returns: 0.19630313135275743

  36. 90

    {80, 64, 32, 57, 49, 49}

    104

    {6, 58, 29, 81, 80, 13}

    Returns: 0.8394366633008992

  37. 85

    {89, 74, 28, 86, 16, 50}

    106

    {77, 49, 44, 97, 7, 30}

    Returns: 0.09950087419073816

  38. 152

    {13, 19, 17, 94, 78, 7}

    107

    {18, 80, 64, 94, 27, 86}

    Returns: 0.062226672739695225

  39. 90

    {67, 38, 36, 17, 71, 37}

    76

    {70, 16, 99, 74, 23, 48}

    Returns: 0.2703034500524742

  40. 100

    {67, 41, 86, 88, 55, 59}

    164

    {26, 51, 24, 26, 12, 91}

    Returns: 0.7983177346915058

  41. 121

    {36, 70, 38, 61, 50, 13}

    121

    {28, 79, 35, 69, 30, 27}

    Returns: 0.501752060427102

  42. 145

    {33, 43, 42, 39, 36, 42}

    119

    {21, 92, 68, 83, 29, 5}

    Returns: 0.2609327938893526

  43. 74

    {1, 45, 38, 46, 69, 97}

    61

    {3, 58, 77, 89, 10, 67}

    Returns: 0.9411406781077755

  44. 94

    {94, 78, 54, 73, 60, 58}

    160

    {53, 58, 61, 21, 9, 62}

    Returns: 0.04536527419664167

  45. 81

    {27, 7, 87, 38, 65, 77}

    70

    {45, 62, 64, 94, 38, 5}

    Returns: 0.9146438656313055

  46. 196

    {96, 29, 12, 89, 46, 7}

    193

    {7, 69, 30, 49, 76, 65}

    Returns: 0.24534383811241348

  47. 18

    {24, 31, 16, 65, 61, 56}

    18

    {70, 16, 76, 24, 17, 68}

    Returns: 0.34812559599367604

  48. 164

    {84, 85, 53, 34, 44, 25}

    199

    {48, 2, 51, 11, 80, 84}

    Returns: 0.30362425458716547

  49. 185

    {68, 65, 99, 14, 20, 53}

    178

    {91, 73, 30, 27, 33, 95}

    Returns: 0.17486496878427826

  50. 155

    {13, 90, 42, 27, 59, 99}

    119

    {93, 79, 30, 91, 70, 62}

    Returns: 0.5819575480418528

  51. 89

    {13, 1, 36, 61, 19, 70}

    103

    {16, 58, 7, 45, 50, 18}

    Returns: 0.11854621851619367

  52. 94

    {32, 87, 68, 95, 49, 81}

    134

    {55, 82, 5, 99, 53, 12}

    Returns: 0.19815474682507994

  53. 193

    {20, 89, 23, 47, 41, 9}

    162

    {50, 52, 6, 75, 50, 58}

    Returns: 0.13750119664901542

  54. 3

    {26, 49, 6, 95, 52, 26}

    5

    {57, 60, 79, 47, 81, 15}

    Returns: 0.017172377495808563

  55. 130

    {75, 23, 77, 69, 99, 26}

    133

    {77, 83, 12, 98, 28, 75}

    Returns: 0.2831248206864896

  56. 75

    {81, 99, 82, 85, 40, 99}

    138

    {60, 59, 8, 23, 20, 86}

    Returns: 0.6959432865451713

  57. 73

    {70, 12, 17, 51, 52, 81}

    79

    {37, 32, 97, 21, 28, 47}

    Returns: 0.4954853514613028

  58. 149

    {86, 71, 100, 88, 84, 68}

    182

    {100, 71, 91, 48, 42, 33}

    Returns: 0.9658509062350724

  59. 59

    {74, 66, 82, 32, 57, 72}

    84

    {3, 25, 26, 89, 48, 41}

    Returns: 0.9689650546244156

  60. 46

    {83, 1, 66, 11, 11, 59}

    22

    {97, 73, 66, 41, 61, 32}

    Returns: 0.9594884367769796

  61. 53

    {31, 40, 59, 94, 84, 31}

    57

    {25, 95, 28, 51, 17, 40}

    Returns: 0.9814866796160062

  62. 200

    {100,50,25,12,6,3}

    200

    {99,49,24,11,5,2}

    Returns: 0.6155775286164739

  63. 200

    {1, 3, 8, 18, 45, 100 }

    200

    {1, 4, 10, 21, 53, 100 }

    Returns: 0.25240407058279035

  64. 200

    {100, 100, 100, 100, 100, 100 }

    200

    {100, 100, 100, 100, 100, 100 }

    Returns: 0.0

  65. 200

    {99, 100, 100, 100, 100, 100 }

    200

    {100, 100, 100, 100, 100, 98 }

    Returns: 0.9980545763195985

  66. 200

    {99, 99, 99, 100, 100, 100 }

    200

    {99, 99, 99, 100, 100, 100 }

    Returns: 0.4800653490181033

  67. 200

    {1, 4, 8, 100, 50, 60 }

    200

    {20, 57, 34, 78, 100, 78 }

    Returns: 1.1748499430056009E-13

  68. 18

    {6, 6, 6, 6, 6, 6 }

    10

    {1, 2, 3, 4, 5, 6 }

    Returns: 0.9999999999999999


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: