Football rivalry (2) P94654


Statement
 

pdf   zip

html

Two long-time rival football teams, let us call them B (for beautiful manners) and M (for miserable — very, very miserable — manners), are playing again. Both teams are exhausted, so the first to score a goal will win the game for sure. At this moment, team B has the ball. If they decide to attack, there is a probability wB that they manage to score, thus winning the game. Hovewer, with probability ℓB they will receive a goal, thus losing the game. With probability 1 − wB − ℓB they will just lose the possesion of the ball. Team B has another option: to pass the ball around. In that case, the possesion of the ball will eventually go to team M. Then we will have a simmetrical situation: If team M goes for an attack, they will immediately win with probability wM, they will immediately lose with probability ℓM, and the ball will go back to team B with probability 1 − wM − ℓM. If they decide to just pass the ball and wait, eventually the possesion of the ball will go back to team B.

Given wB, ℓB, wM and ℓM, and assuming that both teams take the best decisions (to attack or not to attack) and that team B has the ball now, which is the probability that team B will win?

Input

Input consists of several cases, each one with four real numbers wB, ℓB, wM and ℓM between 0 and 1. Assume wB + ℓB ≤ 1 and wM + ℓM ≤ 1.

Output

For every case, print the probability that team B will win with four digits after the decimal point. (The input cases have no precision issues.) A situation where no goal will be scored (an eternal tie) is similar to a fifty-fifty situation. Consequently, print “0.5000” in this case.

Public test cases
  • Input

    1   0   0.7 0.2
    0.3 0.6 1   0
    0   0   0.3 0.6
    0   0   0.1 0
    0.4 0.2 0   1
    0   1   0.4 0.2
    0.4 0.2 0.4 0.2
    0   0   0   0
    

    Output

    1.0000
    0.3000
    0.5000
    0.0000
    0.6667
    0.3333
    0.5714
    0.5000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++ Python