Board coverage issues

Source: Internet
Author: User

In a chessboard of 2^k * 2^k squares, if a square is different from other squares, it is called a special square, which is called a special chessboard. It is obvious that special squares appear on the board in the 4^k case. Thus for any k>=0, there are 4^k different special chessboard. The special chessboard shown is one of the 16 special chessboard in k=2.

650) this.width=650; "Src=" http://images.cnblogs.com/cnblogs_com/lsxqw2004/WindowsLiveWriter/6e8df6c1d310_13ADF/ 1_thumb.gif "width=" 146 "height=" "style=" Border:none;height:auto; "/>

In the board coverage problem, the different forms of the L-type dominoes in 4 are used to cover all squares except special squares on a given special chess card, and any 2 L-type dominoes shall not overlap. It is easy to know that in any 2^k * 2^k chessboard, the number of L-type dominoes used is exactly (4^k-1)/3.

650) this.width=650; "Src=" http://images.cnblogs.com/cnblogs_com/lsxqw2004/WindowsLiveWriter/6e8df6c1d310_13ADF/ 2_thumb.gif "width=" 266 "height=" "style=" Border:none;height:auto;/>

A simple algorithm for solving the checkerboard problem can be designed by using the divide-and-conquer strategy.
When k>0, divide the 2^k * 2^k checkerboard into 4 2^ (k-1) * 2^ (k-1) sub-chessboard as shown.

650) this.width=650; "Src=" http://images.cnblogs.com/cnblogs_com/lsxqw2004/WindowsLiveWriter/6e8df6c1d310_13ADF/ 3_thumb.gif "width=" 156 "height=" 154 "style=" Border:none;height:auto; "/>

Special squares must be located in one of the 4 smaller sub-chessboard, with no special squares in the remaining 3 sub-chessboard. In order to convert the 3 sub-chessboard without special squares into a special chessboard, we can cover the 3 smaller chessboard with an L-shaped domino, as shown above, the squares covered by the L-shaped dominoes on the 3 sub-chessboard become special squares on the chessboard, thus turning the original problem into a 4 smaller checkerboard coverage problem. This segmentation is used recursively until the checkerboard is simplified to a 1x1 checkerboard.

650) this.width=650; "Src=" http://images.cnblogs.com/cnblogs_com/lsxqw2004/WindowsLiveWriter/6e8df6c1d310_13ADF/ 4_thumb.gif "width=" 213 "height=" 204 "style=" Border:none;height:auto; "/>

  Board coverage issues #include<iostream>using namespace std;int board[16][16];int tile=0;  int chessboard (int tr, int tc, int dr, int dc, int  Size) {if (size == 1) return 0;int t=tile++,s=size/2;//  upper left 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);}   Upper Right 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);}   Lower left 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);}   Lower right 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);}} Int main () {chessboard (0,0,3,2,16); for (int i=0;i<16;i++) {for (int j=0;j<16;j++) cout<< Board[i][j]<< " \ t "; Cout<<endl;cout<<endl;}}


Board coverage issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.