#P9567. Tromino Tiling of a Grid with a Missing Cell
Tromino Tiling of a Grid with a Missing Cell
Tromino Tiling of a Grid with a Missing Cell
Given an \(n \times n\) grid (with rows and columns indexed from 1) containing exactly one black cell at \((b_i, b_j)\) and all other cells white, cover all white cells with L-shaped trominoes so that:
- Each white cell is covered exactly once.
- The black cell is not covered.
- Each L-shape (tromino) is defined by four integers \((r, c, h, w)\) where \((r, c)\) is its turning point and the two arms are determined by the nonzero integers \(h\) and \(w\). (The vertical arm covers all cells \((i, c)\) for \(\min(r,r+h) \le i \le \max(r,r+h)\); the horizontal arm covers all cells \((r, j)\) for \(\min(c,c+w) \le j \le \max(c,c+w)\).)
- The parameters satisfy \(1 \le r,c \le n\), \(1 \le r+h \le n\), \(1 \le c+w \le n\), and \(h \neq 0,\; w \neq 0\). In the minimal case, an L-shape covers exactly 3 cells, forming a tromino.
A classical problem is to tile a \(2^k\times2^k\) board with one cell missing using trominoes. In this problem, you are to output any valid tiling (if one exists) by listing the parameters \((r, c, h, w)\) of each L-shape used. The tiling algorithm below (divide and conquer) guarantees a valid answer when \(n\) is a power of 2.
Note: If \(n = 1\), then the grid contains only the black cell and no tromino is placed.
inputFormat
The first line contains three integers: \(n\), \(b_i\), and \(b_j\), where \(n\) is the size of the grid and \((b_i, b_j)\) is the position of the black cell.
outputFormat
First, output the number of L-shapes (trominoes) used. Then, for each tromino, output a line containing four integers \(r\), \(c\), \(h\), and \(w\) representing its turning point and arm directions. The output must correspond to a tiling that covers every white cell exactly once without covering the black cell.
sample
2 1 1
1
2 2 -1 -1
</p>