#P1820. 麻将 加强加强版
麻将 加强加强版
Description
Xiao A found a strange set of Mahjong tiles: it only has number tiles , and there are infinitely many copies of each tile.
A "pair" is two identical tiles (e.g., , ). A "triplet" is three identical tiles (e.g., , ). A "sequence" is three tiles with consecutive ranks (e.g., , ; note that and are not adjacent). "Sequence" and "triplet" are collectively called "melds."
If you can divide your hand into several "melds" (duplicates allowed) plus one "pair," then you can "complete the hand" (i.e., win).
If adding a certain tile to a hand allows it to "complete the hand," then the hand is said to be "waiting for" that tile.
Now Xiao A has randomly drawn tiles. He wants to know which tiles he is "waiting for."
Input Format
The first line contains two positive integers , representing the tile range and the number of tiles in Xiao A's hand.
The next line contains integers giving Xiao A's hand. Each number represents one tile in Xiao A's hand.
Output Format
Output several positive integers on the first line, indicating which tiles Xiao A is "waiting for." Please output them in ascending order.
If Xiao A is not "waiting for" any tile, output QAQ.
4 4
1 2 3 4
1 4
9 13
1 1 1 2 3 4 5 6 7 8 9 9 9
1 2 3 4 5 6 7 8 9
2 2
1 2
QAQ
Hint
- Sample 1 explanation: two cases,
11/234and123/44. - Sample 2 explanation: this shape is the "pure Nine Gates" (纯正九莲宝灯), so it "waits for" every number tile.
Constraints
- This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (10 pts): .
- Subtask 3 (30 pts): .
- Subtask 4 (30 pts): .
- Subtask 5 (20 pts): no special constraints.
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号