TopcoderARCHIVE
Archive/Problems/MarbleBag
SRM · Problem 17874

MarbleBag

Problem statement, definition, constraints, and public examples.

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?

Definition

Class:
MarbleBag
Method:
getProbability
Parameters:
int, int, int
Returns:
double
Method signature:
double getProbability(int red, int blue, int green)
(be sure your method is public)

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

  1. 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.
  2. 0
    0
    100
    Returns: 1.0
    Since the bag only has green marbles, the last one is guaranteed to be green.
  3. 3
    4
    5
    Returns: 0.4166666666666667
← All problems