Statistics

Problem Statement for "PointSystem"

Problem Statement

The game of tennis has a rather unusual scoring system. It can be simplified to the following rule: "If a player has at least four points, and is at least two points ahead of his opponent, that player wins the game." For example, 4-1 and 6-4 are winning scores, whereas 3-0 and 5-4 are not.

We can generalize this class of point systems by introducing two variables, pointsToWin and pointsToWinBy. The new rule is "If a player has at least pointsToWin points, and is at least pointsToWinBy points ahead of his opponent, that player wins the game." For example, the common practice of taking "best two out of three" falls into this class, where pointsToWin = 2 and pointsToWinBy = 1.

You would like to know, given a particular point system and the skills of two players, the probability of an upset. An "upset" is defined as a game where a player of lesser skill beats a player of greater skill. Given an int skill, representing the percent likelihood that the worse player beats the better player on any particular turn, along with pointsToWin and pointsToWinBy, you should return a double between 0 and 1 indicating the odds of an upset.

Definition

Class:
PointSystem
Method:
oddsOfWinning
Parameters:
int, int, int
Returns:
double
Method signature:
double oddsOfWinning(int pointsToWin, int pointsToWinBy, int skill)
(be sure your method is public)

Constraints

  • pointsToWin will be between 1 and 10, inclusive.
  • pointsToWinBy will be between 1 and 5, inclusive.
  • skill will be between 1 and 50, inclusive.

Examples

  1. 2

    1

    40

    Returns: 0.352

    This is the 'best two out of three' game. There are exactly three possible ways for an upset to occur: 1) The worse player scores two consecutive points, with probability 0.4*0.4 = 0.16 2) The better player scores one point, and then the worse player scores two consecutive points, with probability 0.6*0.4*0.4 = 0.096 3) The worse player scores one point, the better player scores one point, and then finally the worse player a second point, with probability 0.4*0.6*0.4 = 0.096 Thus, the total probability is 0.16+0.096+0.096 = 0.352

  2. 4

    5

    50

    Returns: 0.4999999999999998

    When the probability is 50, clearly each player is the same, so each player has a 50% chance of winning.

  3. 3

    3

    25

    Returns: 0.035714285714285705

  4. 10

    5

    48

    Returns: 0.3949566562885549

  5. 1

    4

    19

    Returns: 0.003018293842361875

  6. 9

    1

    24

    Returns: 0.00938185073388358

  7. 2

    4

    43

    Returns: 0.2446403891804691

  8. 2

    4

    3

    Returns: 9.149506804307481E-7

  9. 10

    1

    39

    Returns: 0.16261164304381354

  10. 3

    4

    42

    Returns: 0.21566777043166588

  11. 8

    3

    27

    Returns: 0.014182677355033809

  12. 10

    2

    35

    Returns: 0.07753434802621584

  13. 4

    5

    36

    Returns: 0.05331136440582318

  14. 3

    5

    40

    Returns: 0.11636363636363636

  15. 7

    4

    48

    Returns: 0.41541557608193425

  16. 3

    4

    19

    Returns: 0.003018293842361875

  17. 10

    3

    15

    Returns: 4.9649834934940344E-5

  18. 6

    1

    33

    Returns: 0.11714026864751065

  19. 6

    4

    24

    Returns: 0.006268999307536835

  20. 2

    5

    44

    Returns: 0.23044321230549097

  21. 7

    5

    38

    Returns: 0.07496708917277026

  22. 10

    3

    27

    Returns: 0.008354424610246745

  23. 2

    3

    50

    Returns: 0.49999999999999983

  24. 1

    5

    6

    Returns: 1.0595379673221927E-6

  25. 4

    3

    46

    Returns: 0.37719720065808476

  26. 8

    5

    15

    Returns: 3.9430677631904765E-5

  27. 3

    4

    11

    Returns: 2.332971226964399E-4

  28. 5

    4

    22

    Returns: 0.004985284180102935

  29. 8

    3

    33

    Returns: 0.054031166460224746

  30. 1

    3

    13

    Returns: 0.0033252610867261986

  31. 6

    5

    6

    Returns: 3.752506923513088E-7

  32. 2

    2

    16

    Returns: 0.035010940919037205

  33. 6

    5

    25

    Returns: 0.00361208055840164

  34. 4

    4

    2

    Returns: 1.7346649546680006E-7

  35. 6

    2

    5

    Returns: 2.922912033839778E-6

  36. 1

    2

    34

    Returns: 0.20972423802612483

  37. 2

    2

    10

    Returns: 0.012195121951219511

  38. 6

    5

    2

    Returns: 4.681331729841816E-10

  39. 9

    5

    42

    Returns: 0.15345039304298383

  40. 8

    2

    40

    Returns: 0.1985732411392001

  41. 1

    2

    7

    Returns: 0.005633478960680618

  42. 5

    3

    17

    Returns: 0.003036053386891745

  43. 9

    5

    8

    Returns: 8.332180533119887E-8

  44. 9

    2

    31

    Returns: 0.04118848281606164

  45. 2

    1

    11

    Returns: 0.033638

  46. 7

    5

    10

    Returns: 3.895021845893313E-6

  47. 5

    5

    50

    Returns: 0.4999999999999998

  48. 1

    4

    17

    Returns: 0.0017567893141372188

  49. 1

    5

    4

    Returns: 1.2558672548311644E-7

  50. 9

    5

    31

    Returns: 0.0118228182263838

  51. 9

    2

    12

    Returns: 3.0240524779784205E-5

  52. 7

    4

    9

    Returns: 5.333811408104796E-6

  53. 5

    3

    8

    Returns: 6.912134402628339E-5

  54. 1

    1

    1

    Returns: 0.01

  55. 8

    2

    33

    Returns: 0.07177242867828629

  56. 10

    1

    3

    Returns: 4.254066587798827E-11

  57. 2

    5

    10

    Returns: 1.693480101608806E-5

  58. 4

    5

    29

    Returns: 0.011240584072091355

  59. 9

    5

    13

    Returns: 6.054000139275781E-6

  60. 8

    1

    30

    Returns: 0.05001254005377599

  61. 9

    1

    2

    Returns: 1.0764362527481045E-11

  62. 8

    1

    4

    Returns: 3.274352606107888E-8

  63. 1

    5

    12

    Returns: 4.7148989837743444E-5

  64. 7

    4

    34

    Returns: 0.050787140789304845

  65. 10

    2

    48

    Returns: 0.426213526838083

  66. 9

    2

    38

    Returns: 0.14099043987057447

  67. 4

    4

    12

    Returns: 3.456560423663357E-4

  68. 2

    4

    27

    Returns: 0.018370094769793885

  69. 10

    5

    21

    Returns: 2.734850032311632E-4

  70. 5

    2

    49

    Returns: 0.47267592578044787

  71. 6

    2

    8

    Returns: 4.554672826806804E-5

  72. 6

    1

    1

    Returns: 4.425434338348E-10

  73. 9

    1

    30

    Returns: 0.0402769360542546

  74. 8

    1

    20

    Returns: 0.004239749709824001

  75. 7

    1

    10

    Returns: 9.928548640000001E-5

  76. 4

    5

    15

    Returns: 1.7111471023167378E-4

  77. 8

    5

    36

    Returns: 0.0460605973614878

  78. 6

    2

    30

    Returns: 0.06331923062068968

  79. 5

    5

    48

    Returns: 0.40126103608143454

  80. 9

    1

    30

    Returns: 0.0402769360542546

  81. 7

    4

    42

    Returns: 0.19956702395603976

  82. 2

    3

    19

    Returns: 0.012741965446776889

  83. 8

    3

    11

    Returns: 1.9364280273286726E-5

  84. 9

    5

    32

    Returns: 0.015558722804942745

  85. 7

    3

    31

    Returns: 0.04316016924324729

  86. 10

    5

    50

    Returns: 0.4999999999999991

  87. 10

    5

    49

    Returns: 0.44694092401748997

  88. 1

    1

    50

    Returns: 0.5

  89. 10

    5

    23

    Returns: 6.424438832898403E-4


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: