MarbleBag
Rookie SRM 18 · 2022-10-10 · by erinn
Problem Statement
You have a bag filled with some number of red, blue and green marbles. You begin picking marbles randomly from the bag. What is the probability that the last marble you select is green?
Constraints
- red will be between 0 and 100, inclusive.
- blue will be between 0 and 100, inclusive.
- green will be between 0 and 100, inclusive.
- There will be at least one marble in the bag.
Statement by TopCoder, Inc. — view the original on the archive.
1 1 1 Returns: 0.3333333333333333
The last marble is equally likely to be any of the three, so there's a 1/3 chance it's green.
0 0 100 Returns: 1.0
Since the bag only has green marbles, the last one is guaranteed to be green.
100 100 0 Returns: 0.0
3 4 5 Returns: 0.4166666666666667
63 27 48 Returns: 0.34782608695652173
Submissions are judged against all 6 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MarbleBag with a public method double getProbability(int red, int blue, int green) · 6 test cases · 2 s / 256 MB per case