Volleyball
TCO04 Round 3 · 2004-09-07 · by dgoodman
Problem Statement
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.
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.
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.
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.
8 12 0.4 Returns: 0.046377890909090946
9 6 .4 Returns: 0.8207606501003635
13 11 .45 Returns: 0.8226249999999999
Submissions are judged against all 20 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Volleyball with a public method double win(int sScore, int rScore, double probWinServe) · 20 test cases · 2 s / 256 MB per case