In a checkerboard composed of 2 ^ K * 2 ^ K squares, if there is a square different from other squares, it is called a special square, and it is called a special checkerboard. Obviously, there are 4 ^ K positions in the special square on the board. Therefore, for any k> = 0, there are 4 ^ k different special chessboard. The special checkerboard shown is one of the 16 special checkerboards when k = 2.
In the Board coverage problem, we need to cover all the squares except the special squares on a given special card with different forms of L-shaped dominoes in medium 4, and no two L-type dominoes can overlap. Yi Zhi, in any 2 ^ K * 2 ^ K board, the number of L-type dominoes used is exactly (4 ^ k-1)/3.
With the sub-governance policy, you can design a simple algorithm to solve the Board problem.
When K> 0, split the 2 ^ K * 2 ^ K board into 4 2 ^ (k-1) * 2 ^ (k-1) Sub-boards, as shown in.
The special check box must be located in one of the four smaller check boards. The other three check boxes do not have special check boxes. To convert these three sub-boards without special squares into special ones, we can use an L-shaped bone card to cover the convergence of these three smaller boards, as shown in, the square covered by the L-type dominoes on the three sub-boards becomes a special square on the board, thus turning the original problem into four small-scale board coverage problems. Recursively use this split until the checker is simplified to a 1x1 checker.
The following code is provided:
1 # include <iostream> 2 # include <string. h> 3 using namespace STD; 4 int tile = 1; // The serial number (incrementing) of the L-type bone board 5 Int Board [100] [100]; // 6 /*********************************** * ****************** 7 * input parameters for implementing the checkerboard overwrite algorithm 8 in recursive mode: 9 * tr -- Row 10 * TC in the upper left corner of the current Board -- column number 11 * Dr in the upper left corner of the current Board -- row number 12 * DC in the current special square -- column number in the current special square 13 * size: current chessboard: 2 ^ K14 ************************************* * **************/15 void chessboard (int tr, int TC, int DR, int DC, int size) 16 {17 if (size = 1) // the size of the checkerboard is 1, which indicates Recursion to the base layer 18 return; 19 int T = tile ++; // each increment is 120 int S = size/2; // The row and column number in the middle of the Board (equal) 21 // check whether the special square is in the upper left corner of the chess board 22 if (Dr <tr + S & DC <TC + S) // on the 23 chessboard (TR, TC, Dr, DC, S); 24 else // No. The lower right corner of the sub-board is regarded as a special block 25 {26 Board [tr + s-1] [TC + s-1] = T; 27 chessboard (TR, TC, tr + s-1, TC + s-1, S ); 28} 29 // check whether the special square is 30 if (Dr <tr + S & DC> = TC + S) in the upper right corner of the sub-board. // on the 31 chessboard (TR, TC + S, Dr, DC, S); 32 else // not in, the lower left corner of the sub-board is treated as a special square 33 {34 Board [tr + s-1] [TC + S] = T; 35 chessboard (TR, TC + S, tr + s-1, TC + S, S); 36} 37 // check whether the special square is in the lower left corner of the chess board 38 If (Dr> = tr + S & DC <TC + S) // In 39 chessboard (tr + S, TC, Dr, DC, S); 40 else // not in, the square in the upper-right corner of the sub-board is regarded as a special square 41 {42 Board [tr + S] [TC + s-1] = T; 43 chessboard (tr + S, TC, tr + S, TC + s-1, S); 44} 45 // check whether the special square is in the lower right corner of the game board 46 If (Dr> = tr + S & DC> = TC + S) // In 47 chessboard (tr + S, TC + S, Dr, DC, S); 48 else // not in, the upper left corner of the sub-board is regarded as a special block 49 {50 board [tr + S] [TC + S] = T; 51 chessboard (tr + S, TC + S, tr + S, TC + S, S); 52} 53} 54 55 int main () 56 {57 int size; 58 memset (board, 0, sizeof (board )); 59 cout <"Size of the input board (the size must be the N power of 2):"; 60 CIN> size; 61 int index_x, index_y; 62 cout <"coordinates of the positions of the input special squares:"; 63 CIN> index_x> index_y; 64 cout <Board [index_x] [index_y] <Endl; 65 chessboard (0, 0, index_x, index_y, size); 66 for (INT I = 0; I <size; I ++) 67 {68 for (Int J = 0; j <size; j ++) 69 cout <Board [I] [J] <''; 70 cout <Endl; 71} 72 return 0; 73}