Given two life totals, a hit threshold and a fixed damage, find the probability that vampire 1 wins a turn-based drain fight.
Medium5ProbabilityDynamic programmingSimulationInterviewNo attempts yetTime limit2sMemory limit512 MBFelipinho is hooked on his new RPG about wars between vampire clans. In the game he plays a vampire character who keeps fighting vampires from other clans. Each battle is decided by the attributes of the characters involved and by an ordinary six-sided die.
For simplicity, consider only fights between two vampires, vampire 1 and vampire 2. Each has a life energy, called EV1 and EV2 respectively. An attack strength AT and a damage value D are also fixed.
The fight proceeds in turns as follows. Each turn the die is rolled. If the result is less than or equal to AT, vampire 1 wins the turn; otherwise vampire 2 wins it. The winner drains D life energy from the opponent: the loser's energy decreases by D and the winner's energy increases by D. The fight continues until one of the vampires has an energy less than or equal to zero.
For example, suppose EV1=7, EV2=5, AT=2 and D=4. The die is rolled and shows 3. Vampire 2 wins the turn, so 4 is subtracted from vampire 1's energy EV1 and added to vampire 2's energy EV2. The new values are EV1=3 and EV2=9. If vampire 2 wins the next turn as well, the fight ends.
AT and D stay constant for the whole fight; only EV1 and EV2 change.
Felipinho loves the game, but he finds the fights far too long, and he would like to know his chance of winning in advance so he can decide whether a fight is worth it. Write a program that, given the initial values of EV1 and EV2 together with AT and D, computes the probability that vampire 1 wins the fight.
The input contains several test cases. Each test case is a single line with four integers EV1, EV2, AT and D separated by spaces (1≤EV1,EV2≤10, 1≤AT≤5, 1≤D≤10).
The end of the input is marked by a line containing four zeros separated by spaces. Do not process this line.
For each test case, print a single line with one real number: the probability that vampire 1 wins the fight, expressed as a percentage, with exactly one digit after the decimal point.
Round the exact probability to one decimal place. When the exact value lies exactly halfway (for example, exactly 56.25), round up and print 56.3.