Contracting gas

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 p_(d). However, if you already have a paper from the
marketer, you will lose it with probability q_(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 p_(m).
However, if you already have a paper from the distributor, you will lose
it with probability q_(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 p_(d), q_(m), p_(m) and q_(d)
in this order. All the probabilities are real numbers with at most two
digits after the decimal point. Additionally, p_(d) and p_(m) are at
least 0.1, and q_(m) and q_(d) are at most 0.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.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:19:44.517Z

© Jutge.org, 2006–2026.
https://jutge.org
