Deceitful War (Small)
Time limit5sMemory limit512 MB
Given both players' block weights, compute Naomi's best scores under honest War rules and under optimal lying in Deceitful War.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Game theory
- Solved
- No attempts yet
Problem
Naomi and Ken each have identical looking wooden blocks. Every block weighs more than 0.0kg and less than 1.0kg, and all weights are different.
They play a game called War with the following rules.
- Each player weighs all of their own blocks. A player knows the weights of their own blocks and nothing about the other player's blocks.
- Repeat the following times.
- Naomi picks one of her own blocks. Call its mass
ChosenNaomi. - Naomi tells Ken the value of
ChosenNaomi. - Ken picks one of his own blocks. Call its mass
ChosenKen. - They put the two blocks on opposite pans of a balance scale, and whoever played the heavier block gets one point.
- Both blocks burn up.
- Naomi picks one of her own blocks. Call its mass
Ken has exactly one strategy that maximizes his own score without assuming anything about Naomi's strategy, and he always follows it.
Naomi decides to play a different game called Deceitful War instead. Ken still believes he is playing War. Two rules change.
- Naomi has already weighed Ken's blocks while he was not looking. Naomi knows all weights, and Ken knows only his own.
- Instead of announcing the mass of the block she picked, Naomi announces some number
ToldNaomigreater than 0.0kg and less than 1.0kg. Ken takes that number to beChosenNaomi.
The scale must never expose the lie, so in every round Naomi has to satisfy both of these conditions.
ChosenNaomi>ChosenKenholds if and only ifToldNaomi>ChosenKenholds.ToldNaomiis not equal to the mass of any block Ken holds, because Ken knows that no two blocks weigh the same.
Naomi knows what Ken knows and knows the optimal War strategy Ken follows, so she always predicts the block Ken will play.
You are given the masses of the blocks the two players start with. Find the score Naomi gets when she plays Deceitful War optimally, and the score she gets when she plays War optimally instead. In both cases Ken believes the two are playing War and maximizes his own score.
Two situations, for illustration.
One block is left on each side, Naomi holds 0.5kg and Ken holds 0.6kg. Ken takes the point. If Naomi announced 0.6kg or more, the scale would tip toward Ken and he would catch the lie.
Two blocks are left on each side, Naomi holds 0.7kg and 0.2kg while Ken holds 0.8kg and 0.3kg. Naomi can play her 0.2kg block and claim she picked a 0.6kg one. Ken believes her, plays his 0.8kg block and scores a point. The scale tips toward Ken exactly as he expects, so he never learns that he was deceived. In the next round Naomi plays her 0.7kg block, truthfully says 0.7kg, and scores a point. Had she played War, Ken would have scored two points and Naomi none.
Input
The first line contains the number of test cases . The first line of each test case contains , the number of blocks each player has. The next line contains the masses of Naomi's blocks separated by spaces, and the last line contains the masses of Ken's blocks in the same format.
Every mass is written as a 0, then a decimal point, then 1 to 5 digits. Ken and Naomi do not know that the numbers in the input have at most 5 digits after the decimal point, so Naomi may claim she played a block of 0.5000001kg and Ken has no reason to doubt her.
- All masses given to the two players are different, greater than 0.0 and less than 1.0.
Output
For each test case, print one line in the form Case #x: y z. Here is the test case number starting from 1, is the score Naomi gets when she plays Deceitful War optimally, and is the score she gets when she plays War optimally.