GG NO RE OMG CHEATZ
Time limit3sMemory limit256 MB
Find the fewest extra attacker units that lift the dice-battle win chance to at least 75 percent.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Probability, Binary search
- Solved
- No attempts yet
Problem
You do not need to know the board game Risk to solve this problem. Every die in this problem is a six sided die.
Rizk is a Bulgarian variant of Risk. Two players fight, each commanding an army. On your turn you either attack or add units to your army, never both. An attack works like this.
Player A attacks with units and player B defends with units. The attacker has dice available and the defender has dice available. One attack repeats the following steps.
- Player A rolls dice.
- Player B rolls dice. This differs from ordinary Risk.
- Both players sort their dice from highest to lowest and compare them pair by pair. For example, if player A rolled 2, 5, 1, 3 and player B rolled 4, 1, 3, then 5 meets 4, then 3 meets 3, then 2 meets 1. The leftover low rolls of the player who threw more dice take part in no comparison.
- In each comparison the losing player loses one unit. The defender wins ties. In the example above, A loses 1 unit and B loses 2 units.
- If both players still have at least 1 unit, go back to step 1.
The player who still has units at the end wins the battle. Exactly one player always has units left.
Mike and his brother have been playing for hours. Neither dares to attack, because both fear losing. It is Mike's turn, and he has decided to cheat a little in order to win. He attacks only if his chance of winning this turn is at least 75 percent. Mike has units and his brother has units. How many units does Mike have to sneak into the game so that his chance of winning this turn is at least 75 percent?
Input
The first line contains one integer , the number of test cases. Each of the next lines contains four integers , , , separated by spaces, with the meaning given above.
- No test case has a winning probability closer to than when a unit is added to or removed from Mike's army.
Output
For each test case, print on its own line the smallest number of extra units Mike needs so that his chance of winning this turn is at least 75 percent. Print 0 if he already has at least a 75 percent chance.