#P7144. [THUPC 2021 初赛] 狗蛋和二五仔
[THUPC 2021 初赛] 狗蛋和二五仔
Description
Xiao E likes to play card games with the teacher in different ways. Recently, they invented a new mode called "Gou Dan and Er Wu Zai".
The rules are as follows:
At the start of the game, Xiao E and the teacher each have HP, and each has cards in hand. All cards are identical. Each player may place cards in front of themselves; initially, there are no cards on either side.
The two players take turns to act. At the beginning of each of a player's turns, they first draw one card. The operation "draw one card" means: if the number of cards in hand is less than , take one more card into the hand; if the hand already has exactly cards, then no more cards can be drawn. There are types of actions.
-
Skill. Decrease your own HP by , then draw one card.
-
Attack. Specifically, the player may choose a card in front of themselves that has not attacked yet this turn, and either choose one card in front of the opponent to perish together, or choose a card in front of themselves that has not attacked yet this turn to make the opponent's HP decrease by . If it is the latter, mark the chosen card as having attacked.
-
Play a card. You may do this only if the number of cards in front of you is less than and you have at least one card in hand. First perform the following process times:
- Randomly choose a character and decrease its HP by . This character can be yourself, the opponent, or a card in front of either side. If there are a total of cards on the field (both sides combined), then the probability of choosing any particular character is . If the chosen character is a card and its HP becomes , destroy it. If the chosen character is a player and their HP becomes , that player immediately loses the game.
After the times are completed, place one card from your hand in front of yourself. The card's HP is . This card is considered to have already attacked during this turn.
-
End the turn; then it becomes the opponent's turn.
Within one turn, a player may perform multiple actions, but the sum of the number of Skill actions and Play-a-card actions cannot exceed . Except for ending the turn, there is no restriction on the order of these actions. For example, you may play a card first, then use Skill, then play another card. Before ending the turn, the player must perform at least one action of any type in that turn.
At any moment, if a player's HP is less than or equal to , then that player loses the game.
After several turns, it is now just before the start of Xiao E's turn. Xiao E wants you to analyze: if both sides adopt optimal strategies, what is the probability that Xiao E wins from now on.
Input Format
The first line contains two positive integers , representing the number of test cases and the upper limit of the number of Skill actions plus Play-a-card actions in each turn.
For each test case, the first line contains two positive integers , representing Xiao E's and the teacher's current HP. It is guaranteed that .
The second line contains a non-negative integer , followed by positive integers , indicating that there are cards in front of the teacher, with HP values . It is guaranteed that , .
The third line contains a non-negative integer , followed by positive integers , indicating that there are cards in front of Xiao E, with HP values . It is guaranteed that , .
The fourth line contains two non-negative integers in , representing the number of cards in hand of the teacher and Xiao E, respectively.
Before you arrived, the teacher may have cheated; you do not need to verify whether the input state can really occur after several rounds of the game.
Output Format
For each test case, output one real number per line, representing the probability that Xiao E wins when both sides make optimal decisions. Your answer is considered correct if its absolute error from the standard answer does not exceed .
1 5
1 1
0
0
0 1
0.500000000
1 4
5 14
1 1
1 1
1 0
0.041879441
Hint
[Sample Explanation #1]
At the start of the turn, Xiao E draws one card. Now Xiao E has cards in hand, the teacher has no cards in hand, and there are no cards in front of either side. Both players have HP equal to . Under optimal play, Xiao E cannot use Skill, because after using it his HP would be less than or equal to and he would lose immediately; Xiao E cannot attack, because he has no cards in front of him; Xiao E also cannot end the turn, because he has not performed any action this turn yet. Therefore, Xiao E's optimal strategy is to play a card. Then a character among Xiao E and the teacher is randomly chosen, and that character's HP decreases by and they lose the game. So Xiao E's winning probability is .
[Subtasks]
It is guaranteed that .
[Afterword]
In the end, Xiao E still defeated the teacher.
"Teacher, once you play enough Warlock you will know how to play it. You still haven't played enough."
"Is bragging done like this nowadays? Bro, do you know how many Warlock wins I have, huh? I'm telling you, there isn't a single person in the world with more Warlock wins than me."
[Source]
From the preliminary contest of the 2021 Tsinghua University Student Algorithm Contest and Collegiate Invitational (THUPC2021).
Solutions and other resources can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5
京公网安备 11011102002149号