Connection Status:
Competition Arena > MarbleBag
Rookie SRM 18 · 2022-10-10 · by erinn · Simple Math
Class Name: MarbleBag
Return Type: double
Method Name: getProbability
Arg Types: (int, int, int)
Problem Statement

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.
Examples
0)
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.

1)
0
0
100
Returns: 1.0

Since the bag only has green marbles, the last one is guaranteed to be green.

2)
100
100
0
Returns: 0.0
3)
3
4
5
Returns: 0.4166666666666667
4)
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.

Coding Area

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

Submitting as anonymous