Marble Madness
Time limit1sMemory limit256 MB
Given starting counts of black and white marbles and the two-draw replacement rules, print the probability the last remaining marble is black or white.
- Level
Medium5 of 10
- Topics
- Math
- Solved
- No attempts yet
Problem
Oyvind tests job applicants with games. This one starts with a bag holding black marbles and white marbles. Outside the bag you have an unlimited supply of marbles of both colors.
The game runs in rounds. In each round you take two marbles out of the bag at random and put one marble back in. The color you put back depends on what came out.
- Two white marbles came out: put a black marble in.
- One black marble and one white marble came out: put a white marble in.
- Two black marbles came out: put a black marble in.
Each round leaves the bag with one marble fewer, so the game ends when a single marble remains. Given the starting counts, find the probability that this last marble is black and the probability that it is white.
Input
The first line has the number of test cases . Each of the next lines has two integers and separated by one space, the number of black marbles and the number of white marbles in the bag at the start.
Output
Print one line for each test case with two numbers separated by one space. The first number is the probability that the last marble is black, the second is the probability that it is white. Print both probabilities with exactly two digits after the decimal point.