#P10457. 占卜DIY
占卜DIY
Problem Description
lyd learned how to use playing cards to do DIY fortune telling. The method is as follows: there is a deck of cards with both Jokers removed. After shuffling, split them evenly into piles, numbered . Each pile has cards. The -th pile is called the “life pile”, which means you have lives. Among all cards, the four cards are called the Grim Reaper.
In the initial state, all cards are placed face down.
The process is:
- Draw the top card (the first card) from the life pile.
- Flip this card face up, and place it on top of the pile whose number matches the card value. (For example, if you draw , place it face up on top of pile . If you draw , place it on top of pile . Note that it must be placed face up.)
- From the pile where you just placed the card, draw the bottom card (the last card), and repeat step . (For example, last time you drew and placed it on top of pile . Now you draw the last card of pile and find it is , then you place it on top of pile , and so on.)
- If you draw a during the drawing process, it means you lose one life. Discard this , then restart from step .
- After all four lives are lost, count how many face-up cards are on top of each pile. If the same value has cards that are face up (for example, four cards), then it is called “opening a pair”. Of course, four cards do not count.
- Count how many pairs are opened in total. Opening pairs is called “extremely unlucky”, pairs is “very unlucky”, pairs is “unlucky”, pairs is “slightly unlucky”, pairs is “neutral”, pairs is “slightly lucky”, pairs is “lucky”, pairs is “very lucky”, and pairs is “all flowers bloom, extremely lucky”.
If you still do not understand, please refer to the sample.
Input Format
There are lines in total, each describing what cards are in that pile (suits are ignored; only values are given). For each pile, the input order is from top to bottom.
For easier input, use to represent .
Output Format
Output the total number of opened pairs.
8 5 A A
K 5 3 2
9 6 0 6
3 4 3 4
3 4 4 5
5 6 7 6
8 7 7 7
9 9 8 8
9 0 0 0
K J J J
Q A Q K
J Q 2 2
A K Q 2
9
Hint
Note: After the first life is lost, the first piles become:
A A A 8
K 5 3 2
3 9 6 0
4 4 3 4
5 5 3 4
6 6 5 6
7 7 7 7
8 8 8 9
9 9 0 0
0 K J J
J Q A Q//The K drawn here causes a death.
J Q 2 2
The second life is lost immediately because there is a in the life pile, so nothing changes.
After the third life is lost, the first piles become:
A A A A
2 2 2 K
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
0 0 0 0//The K drawn here causes a death.
J J J Q
Q Q J Q
After the fourth life is lost, the first piles become:
A A A A
2 2 2 2//The K drawn here causes a death.
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
7 7 7 7
8 8 8 8
9 9 9 9
0 0 0 0
J J J Q
Q Q J Q
Finally, among all face-up cards, the pairs are opened. (Note: although the last card of pile is also , it was not flipped face up, so it cannot be counted.) Therefore, output .
Translated by ChatGPT 5