Board coverage issues

Source: Internet
Author: User

In a checkerboard consisting of a 2^k * 2^k, there is a square that is different from the other, and how to cover the other squares of this particular square, using the following four kinds of L-shaped dominoes.


Four L-type dominoes such as 1



Figure 1

Special squares in the chessboard 2



Figure 2

The basic principle of the implementation is to divide the chessboard of the 2^k * 2^k into four 2^ (k-1) * 2^ (K-1), the special squares must be in one of the sub-chessboard, if the special squares in a certain sub-chessboard, continue to recursively process the sub-chessboard, until only one square in this sub-chessboard if the special party Lattice is not in a certain sub-chessboard, the corresponding position in the sub-chessboard is set to bone grade, the non-special grid of the Board into a special box of the sub-chessboard, and then recursively processing the sub-chessboard. The above principle is shown in 3.



Figure 3

Java implementation with bug version:

1  Public classChessboard {2     3      Public Static intI=0;4      Public Static intsize=10;5      Public Static intBoard[][] =New int[size][size];6     7      Public Static voidChessboard (intTrintTcintDrintdcintsize) {8         if(size==1)return;//the chessboard is no longer overwritten when there is only one lattice9         intS=SIZE/2;//Split BoardTen         intt=++i; One          A         //overlay the upper left corner of the chessboard -         if(dr<tr+s&&dc<tc+s) -             //Special squares in this chessboard the chessboard (tr,tc,dr,dc,s); -         Else{//there are no special squares in this chessboard -             //overwrite the lower right corner -board[tr+s-1][tc+s-1]=T; +             //cover the remaining squares -Chessboard (tr,tc,tr+s-1,dc+s-1, s); +         } A          at         //overlay Right-hand corner checkerboard -         if(dr<tr+s&&dc>=tc+s) -             //Special squares in this chessboard -Chessboard (tr,tc+s,dr,dc,s); -         Else{//there are no special squares in this chessboard -             //overwrite the lower left corner inboard[tr+s-1][tc+s]=T; -             //cover the remaining squares toChessboard (tr,tc+s,tr+s-1,tc+s,s); +         } -          the         //overlay The lower left corner of the chessboard *         if(dr>=tr+s&&dc<tc+s) $             //Special squares in this chessboardPanax NotoginsengChessboard (tr+s,tc,dr,dc,s); -         Else{//there are no special squares in this chessboard the             //overwrite the upper right corner +board[tr+s][tc+s-1]=T; A             //cover the remaining squares theChessboard (tr+s,tc,tr+s,tc+s-1, s); +         } -          $         //Overlay Right bottom corner chessboard $         if(dr>=tr+s&&dc>=tc+s) -             //Special squares in this chessboard -Chessboard (tr+s,tc+s,dr,dc,s); the         Else{//there are no special squares in this chessboard -             //overwrite upper left cornerWuyiboard[tr+s][dc+s]=T; the             //cover the remaining squares -Chessboard (tr,tc,tr+s,dc+s,s); Wu         } -          About     } $      -      Public Static voidMain (string[] args) { -Chessboard (0, 0, 2, 2, 4); -          for(inti=0;i<4;i++) A              for(intj=0;j<4;j++) +             { the                 if(j==0) - System.out.println (); $System.out.print ("" +board[i][j]); the             } the     } the  the}

There is no guarantee that the sub-chessboard with no special squares in the chessboard function is properly overwritten.

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.