Algorithm Experiment 1: Board coverage time limit:1 Sec Memory limit:64 MB submit:2798 solved:702 [submit][status][discuss] Description
In a chessboard of 2k x 2k Squares, a square is different from the other squares, which is called a special square and is called a special chessboard. In the problem of board coverage, the 4 different forms of the L-shaped dominoes are used to cover all squares on a given special chessboard except for special squares, and any 2 L-type dominoes must not overlap.
Mouth and mouth mouth opening
Mouth mouth, mouth, mouth, mouth
Input
K,DR,DC. K definition as before, DR,DC indicates the line number and column number of the special square 1= < K < =6
Output
According to the upper left, upper right, lower left, lower right, the order is solved by divide-and-conquer method. Special check mark 0, other positions in the order of the above.
Sample Input
2 1 1
Sample Output
HINT
Understand the process of recursive execution and understand the method of division and treatment.
Source
Idea: Divide and conquer--divide the big into similar small to solve, the middle of the square as a special point (first divided into 4 small
Square, find the square with no special points, and the other 3 is the middle point of the large square as a special point),
3 special points are connected to a top L domino, so that each small square has a special point, when 2x2, no matter
Where the special points can be combined with L dominoes a square, then for 1x1, end;
#include <stdio.h>intts[ -][ -];inttile=1;voidChesint,int,int,int,int);voidChesintH1,intL1,intXintYintsize) { intt,s; if(size==1) return ; T=tile++; S=size/2; if(x<s+h1&&y<s+L1) ches (h1,l1,x,y,s); Else{ts[s+h1-1][s+l1-1]=T; Ches (H1,l1,s+h1-1, s+l1-1, s); } if(x<s+h1&&y>=l1+s) ches (H1,l1+s,x,y,s); Else{ts[h1+s-1][l1+s]=T; Ches (H1,l1+s,h1+s-1, l1+s,s); } if(x>=h1+s&&y<l1+s) ches (H1+s,l1,x,y,s); Else{ts[h1+s][l1+s-1]=T; Ches (H1+s,l1,h1+s,l1+s-1, s); } if(x>=h1+s&&y>=l1+s) ches (H1+s,l1+s,x,y,s); Else{ts[h1+s][l1+s]=T; Ches (H1+s,l1+s,h1+s,l1+s,s); }}intMain () {intN,x,y,size=1, I,j; scanf ("%d",&N); scanf ("%d%d",&x,&y); while(n--) Size*=2; Ches (0,0, x,y,size); for(i=0; i<size;i++) { for(j=0; j<size;j++) printf ("%d", Ts[i][j]); printf ("\ n"); } return 0;}
[Submit] [Status] [Discuss]
"Checkerboard Overlay" (simple)--divide and conquer algorithm