Statistics

Problem Statement for "Volleyball"

Problem Statement

In the current "rally scoring" used in volleyball, each serve results in one point, either for the serving team or for the receiving team. Whoever wins the point is the server on the next point. The winning team is the first team to win at least 15 points and be at least 2 points ahead of the other team.

Suppose that two teams are playing a game, and that they are evenly matched. On each point, whichever team serves has a fixed probability, probWinServe, that they will win the point. (Of course, the receiving team will win the point with probability 1.0 - probWinServe.)

Create a class Volleyball that contains a method win that is given sScore (the current score of the serving team), rScore (the current score of the receiving team), and probWinServe. It returns the probability that the serving team will win the game.

Definition

Class:
Volleyball
Method:
win
Parameters:
int, int, double
Returns:
double
Method signature:
double win(int sScore, int rScore, double probWinServe)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

  • sScore and rScore will be between 0 and 100 inclusive.
  • probWinServe will be greater than or equal to 0.01
  • probWinServe will be less than or equal to .99
  • If either sScore or rScore is greater than 14, then sScore=rScore or else sScore=rScore+1.
  • If sScore equals 0, then rScore will also be 0.

Examples

  1. 13

    13

    .5

    Returns: 0.5

    The teams are tied, and it doesn't matter who is serving since probWinServe is 0.5. So the chance of either team winning is the same.

  2. 1

    14

    0.01

    Returns: 3.355704697986578E-27

    In order for the serving team to win this game it would have to win its next 13 serves and then do well after that. So its probability of winning is less than .01 to the 13th power.

  3. 8

    12

    0.4

    Returns: 0.046377890909090946

  4. 9

    6

    .4

    Returns: 0.8207606501003635

  5. 13

    11

    .45

    Returns: 0.8226249999999999

  6. 14

    14

    0.4

    Returns: 0.45454545454545453

  7. 13

    14

    .4

    Returns: 0.18181818181818182

  8. 19

    18

    .2

    Returns: 0.6923076923076923

  9. 4

    3

    0.99

    Returns: 0.9058476778308387

  10. 4

    3

    0.01

    Returns: 0.6662085066547871

  11. 0

    0

    .561111

    Returns: 0.5092217353167382

  12. 85

    84

    .111

    Returns: 0.6799856011519078

  13. 85

    85

    .111

    Returns: 0.3599712023038157

  14. 14

    0

    .1

    Returns: 0.9999999999999678

  15. 1

    14

    .99

    Returns: 0.8603147284303606

  16. 7

    2

    .34

    Returns: 0.9286294531682486

  17. 100

    100

    0.01

    Returns: 0.33557046979865773

  18. 15

    15

    0.9

    Returns: 0.8333333333333334

  19. 100

    99

    0.23

    Returns: 0.6968503937007875

  20. 100

    99

    0.01

    Returns: 0.667785234899329


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: