"Recursive" checkerboard Overlay

Source: Internet
Author: User

Problem Description:

In a checkerboard of 2^k*2^k squares, there is a grid that differs from other squares, called special squares.

Now invite 4 different L-shaped dominoes to cover all squares of a given chessboard except for special parties.

For example: This is a k=2 when the board, the special point coordinates (0,1).


Four L-type dominoes



Program code:


#include <stdio.    H> #define KEY 8//order of the chessboard int ar[key][key]={0};  A two-dimensional array saves the board, the initial value is full 0int tile=1;   flag void Chessboard (int tr,int tc,int dr,int dc,int size) {int s=size/2; Split Checkerboard int flag;if (size==1) return; flag=++tile;//If the special point is in the upper left corner if (dr<tr+s && dc<tc+s) chessboard (TR,TC,DR,    Dc,s);      In the words, recursive else {ar[tr+s-1][tc+s-1]=flag; If not, assign the lower right corner of the chessboard in the upper-left corner as a sign ... Below are three similar chessboard (tr,tc,tr+s-1,tc+s-1,s); }//If the special point is in the upper right corner if (dr<tr+s && dc>=tc+s) chessboard (tr,tc+s,dr,dc,s); else {ar[tr+s-1][tc+s]=flag; chessboard (tr,tc+s,tr+s-1,tc+s,s);} If the special point is in the lower left corner if (dr>=tr+s && dc<tc+s) chessboard (tr+s,tc,dr,dc,s); else {ar[tr+s][tc+s-1]=flag; chessboard (tr+s,tc,tr+s,tc+s-1,s);} If the special point is in the lower right corner if (dr>=tr+s && dc>=tc+s) chessboard (tr+s,tc+s,dr,dc,s); else {ar[tr+s][tc+s]=flag; chessboard (tr+s,tc+s,tr+s,tc+s,s);}} void init (int x,int y)//Initializes a point for the special point {ar[x][y]=1;} int main () {int i,j;i=4;j=5;init (I,J); chessboard (0,0,i,j,8); for (i=0;i<8;i++) {for (j=0; j<8;j++) printf ("%2d", Ar[i][j]);p UTS ("");}} 
Executes the result.



"Recursive" checkerboard Overlay

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.