Contracting gas P33955


Statement
 

pdf   zip

Some time ago, professor Oak bought an old flat that had no gas contract. What follows is a simpliflied model of the nightmare that he had to suffer.

To acquire gas, you need two papers: one from the gas distributor, and another from the gas marketer. Initially, you have none of them. When you try to get a paper from the distributor, you will get it with probability pdp_d. However, if you already have a paper from the marketer, you will lose it with probability qmq_m (the distributor will decide that it is not good enough). Simetrically, when you try to get a paper from the marketer, you will get it with probability pmp_m. However, if you already have a paper from the distributor, you will lose it with probability qdq_d. You spend a whole day every time that you try to get a paper. You win this stupid game when you first manage to have a valid paper from both the distributor and the marketer.

Given all this information, and assuming an optimal strategy, what is the expected number of days to get both papers and therefore gas?

Input

Input consists of several cases, each with pdp_d, qmq_m, pmp_m and qdq_d in this order. All the probabilities are real numbers with at most two digits after the decimal point. Additionally, pdp_d and pmp_m are at least 0.10.1, and qmq_m and qdq_d are at most 0.90.9.

Output

For every case, print with four digits after the decimal point the optimal expected number of days to get gas. The input cases have no precision issues.

Public test cases
  • Input

    1 0 1 0
    1 0 1 0.5
    0.23 0.5 0.42 0.9
    0.1 0.9 0.1 0.9
    

    Output

    2.0000
    2.0000
    20.6156
    920.0000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++