#P2790. ccj与zrz之积木问题
ccj与zrz之积木问题
Description
From left to right there are blocks, numbered from to . Simulate the following 4 operations (here and are block numbers; “return to initial position” means, for example, block goes back to position ):
- : Return all blocks above and above to their initial positions, then place on top of .
- : Return all blocks above to their initial positions, then place on the top of the stack containing .
- : Return all blocks above to their initial positions, then move together with all blocks above it as a whole onto .
- : Move together with all blocks above it as a whole onto the top of the stack containing .
- Stop when encountering . If and are in the same stack, the instruction is illegal and should be ignored.
Finally, output the list of blocks at each position, in order from bottom to top.
Input Format
The first line contains an integer .
Then follow several lines, each containing one instruction (the syntax will be correct). Stop when encountering .
Output Format
Output exactly lines. On the -th line, output followed by a colon, then a space, then all the blocks at position , listed from bottom to top.
10
move 9 onto 1
move 8 over 1
move 7 over 1
move 6 over 1
pile 8 over 6
pile 8 over 5
move 2 over 1
move 4 over 9
quit
0: 0
1: 1 9 2 4
2:
3: 3
4:
5: 5 8 7 6
6:
7:
8:
9:
Hint
Constraints and Notes
For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号