#P3681. Plate Stacking Game
Plate Stacking Game
Plate Stacking Game
Luka is very good at solving Tower of Hanoi problems. He has invented a game using plates and poles that is similar to the Tower of Hanoi. The game features n different sized plates and 36 poles. The plates are numbered from 1 to n in increasing order of size (i.e. plate 1 is the smallest and plate n is the largest). The poles are arranged in a 6×6 matrix. The rows are numbered 1 to 6 from top to bottom and the columns are numbered 1 to 6 from left to right.
At the beginning of the game, all n plates are stacked on the pole at coordinate (1,1). In each move, the player can choose any pole that has at least one plate and remove a contiguous block of plates from the top. Then the player selects another pole to the right (i.e. with the same row and a larger column index) or below (i.e. with the same column and a larger row index) and places the block on top of the stack on that pole. Note that the order of the block is preserved when moving (i.e. it is not reversed).
The goal is to move all plates to the pole at coordinate (6,6) so that the stack on (6,6) is in strictly decreasing order from bottom to top (i.e. the bottom plate is the largest and the top plate is the smallest). It can be shown that a solution always exists.
The movement constraints can be expressed in terms of coordinates: if a move is made from pole (r, c) to pole (r', c'), then either
\( r' = r \) with \( c' > c \) (a move to the right) or
\( c' = c \) with \( r' > r \) (a move downward).
inputFormat
The input consists of a single integer n representing the number of plates.
\( 1 \le n \le 10^5 \) (for example).
outputFormat
First, output an integer m indicating the number of moves used. Each of the following m lines should describe one move with five integers: r1 c1 r2 c2 k, where (r1, c1) is the source pole, (r2, c2) is the destination pole, and k is the number of plates moved in that action.
The moves must satisfy the rules described and the final state must have all plates on pole (6,6) in descending order from bottom to top.
sample
1
2
1 1 1 6 1
1 6 6 6 1
</p>