Title: In a chessboard of 2^k x 2^k squares, if a square is different from the other squares, it is called a special square and is called a special chessboard. Now use 4 different forms of L-shaped dominoes to cover all squares except special squares on a given special chessboard, and any 2 L-type dominoes must not overlap. Explain what is the L-type Domino: It is a corner of three squares, there are four kinds;
Idea: A chessboard is divided into four small chessboard, along the midpoint of each side of the split, special squares must be located in one of the 4 smaller chessboard, the remaining 3 sub-chessboard without special squares. In order to convert the 3 sub-chessboard with no special sub-chessboard into a special chessboard, we can use an L-shaped domino to cover the convergence of the 3 smaller chessboard, recursively go down, and when the length of the checkerboard is 1 o'clock terminated;
The code is as follows:
#include <iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<Set>#include<queue>#include<vector>using namespacestd;inttot;intboard[ the][ the];voidChessboard (intTrintTcintDrintdcintsize) { if(size==1)return ; intt=tot++; ints=size/2; if(dr<tr+s&&dc<tc+s) chessboard (tr,tc,dr,dc,s); Else{board[tr+s-1][tc+s-1]=T; Chessboard (Tr,tc,tr+s-1, tc+s-1, s); } if(dr<tr+s&&dc>=tc+s) Chessboard (TR,TC+s,dr,dc,s); Else{board[tr+s-1][tc+s]=T; Chessboard (TR,TC+s,tr+s-1, tc+s,s); } if(dr>=tr+s&&dc<tc+s) Chessboard (tr+s,tc,dr,dc,s); Else{board[tr+s][tc+s-1]=T; Chessboard (tr+s,tc,tr+s,tc+s-1, s); } if(dr>=tr+s&&dc>=tc+s) Chessboard (tr+s,tc+s,dr,dc,s); Else{board[tr+s][tc+s]=T; Chessboard (tr+s,tc+s,tr+s,tc+s,s); }}intMain () {intdr,dc,s; printf ("the input format is: Special square horizontal axis, ordinate board edge length \ n"); while(SCANF ("%d%d%d", &dr,&dc,&s)! =EOF) {Tot=1; memset (board,0,sizeof(board)); Chessboard (0,0, dr,dc,s); for(intI=0; i<s;i++) { for(intj=0; j<s;j++) printf ("%-2d", Board[i][j]); cout<<Endl; } } return 0;}
Run:
Board coverage (divide and conquer method)