Coin tossing
Time limit2sMemory limit512 MB
Given head counts from tossing two coins whose head probabilities are independent uniform on [0,1], compute the probability that the first coin's probability is smaller.
- Level
Medium7 of 10
- Topics
- Probability, Math, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
A machine makes coins that land heads with probability and tails with probability . Here is a number between 0 and 1, and the machine has no setting for it. The machine picks at random while it makes a coin, so is uniform on the interval .
The machine made two coins. Coin 1 has probability and coin 2 has probability . Both and are uniform on and independent of each other, and there is no way to read off their actual values.
Coin 1 was tossed times and came up heads times. Coin 2 was tossed times and came up heads times. Given these observations, write a program that computes the probability that .
Input
The first line contains the number of test cases ().
Each of the next lines holds one test case: , , , , separated by spaces. (, , , )
Output
For each test case, print the probability that on its own line. Round at the seventh decimal place and print exactly six digits after the decimal point. For example, print 0.800000 when the probability is .