2.2.1 Remaining Chessboard

xiaoxiao2021-03-06  79

Defective Chessboard is a chessboard with 2k × 2K part of the chessboard, which is just a square disabled. Figure 2 - 3 gives a variety of possible incontinence chessboards at K ≤ 2, where the incomplete checkered is expressed. Note that when k = 0, there is only one possible incontinence board (shown in Figure 1 4 - 3 A). In fact, for any K, there is more than 22K different flapboards.

The problem of incontinence chessboards requires three-grid (T R I O M I N o E S) to cover the lack of chessboard (as shown in Figure 1 4 - 4). In this coverage, two three-grade plates cannot overlap, and the three-grade plates cannot cover the incomplete checkered, but must overwrite all other checkered. In this limitation, the total number of three grades required is (22k ​​-1) / 3. You can verify (22k ​​-1) / 3 is an integer. K is an incomplete chessboard is easily covered because it has no non-disabled checkered checkered, the number of three-grade sheets for coverage is 0. When k = 1, there is existently three non-disabled checkered squares, and these three checkers can be covered by three graphs in one direction in Figure 1 4 - 4.

The method of creating a division can solve the problem of the incomplete board. This method can convert the problem of 2K × 2K-incomplete chessboard to cover smaller incidental chessboards. 2k × 2K chessboard A natural division method is to divide it as shown in Figure 1 4 - 5 A. 4 2k - 1 × 2K - 1 chessboard. Note that after this division is completed, there is only one checkerboard in 4 small chessboards (because the original 2k × 2k chessboard has only one incomplete checkered). First cover the 2k-1 × 2k-1-flapped chessboard containing the incomplete checkered checker, then convert the remaining three small chessboards into the incontinence chessboard, put a three-piece plate in the corner formed by these three small chessboards On, as shown in Figure 14-5B, the incomplete square in which the original 2k × 2k chess board falls into the upper left corner of 2K - 1 × 2k - 1 chessboard. This segmentation technology can be used to cover 2K × 2K-incomplete chessboard. When the size of the board is reduced to 1 × 1, the recursive process is terminated. At this point 1 × 1 board, only one square and this is disabled, so there is no need to place the three grades.

The algorithm of the above points can be prepared as a recursive C function Ti L E B O A R d (see program 1 4 - 2). This function defines a global two-dimensional integer variable B O A R d to represent a chessboard. B O A R D [0] [0] indicates the checkered square in the upper left corner of the checkerboard. This function also defines a global integer variable T I L E whose initial value is 0. The input parameters of the function are as follows:

• The rigs in the upper left corner of the TR checkerboard.

? The top left corner of the TC board is listed.

? DR hiking squares.

? DL remaining square.

? The number of rows or columns of the Size board.

The call format of Ti L E B O A R d function is Ti L E B O A R D (0, 0, DR, DC, SIZE), where S i z e = 2k. The number of three-grade sheets required to cover the incontinence chessboard is (S I Z E2 -1) / 3. The function Tileboard uses integers 1 to (S i z e2-1) / 3 to represent these three-grade plates, and mark the non-hardened checkered by the three-grade sheet with the label of the three sheets.

Let T (k) to override the time required for the function Ti L E B O A R D cover a 2k × 2k-lapse chessboard. When k = 0, S i z e is equal to 1, covering it will cost constant time d. When k> 0, a function call for 4 recursive will be carried out, and these calls take to 4T (k-1). In addition to these times, IF condition testing and covering 3 non-disabled characters also require time, assuming that these additional time is represented by constant c. You can get the following recursive expression:

Program 14-2 cover the incontinence board

Void Tileboard (int TR, int TC, INT DR, INT DC, INT Size) {// overrides the incomplete board

IF (size == 1) return;

INT T = Tile , // Number of three-grade used

s = size / 2; // quadrant size

/ / Cover the left quadrant

IF (DR

// The incomplete checkered

Ti L E B O A R d (T R, TC, DR, DC, S);

Else {// There is no incomplete checkered in this quota

// put the three-grade plate T in the lower right corner

BOARD [TR S - 1] [TC S - 1] = T;

// Coverage the rest

Ti L E B O A R D (T R, Tc, Tr S-1, TC S-1, S);

/ / Cover the right quadrant

IF (DR = tc s)

// The incomplete checkered

Ti L E B O A R D (T R, Tc S, DR, DC, S);

Else {// There is no incomplete checkered in this quota

// put the three-grade plate T in the lower left corner

Board [TR S - 1] [TC S] = T;

// Coverage the rest

Ti L E B O A R D (T R, TC S, TR S-1, Tc S, S);}

/ / Cover the left quadrant

IF (DR> = TR S && DC

// The incomplete checkered

Tileboard (Tr S, TC, DR, DC, S);

Else {// put the three-piece plate T in the upper right corner

Board [tr s] [tc s - 1] = T;

// Coverage the rest

Tileboard (TR S, TC, TR S, TC S-1, S);}

// Cover the right quarter limit

IF (DR> = TR S && DC> = TC S)

// The incomplete checkered

Tileboard (Tr S, TC S, DR, DC, S);

Else {// put the three-grade plate T in the upper left corner

Board [tr s] [tc s] = t;

// Coverage the rest

Tileboard (tr s, tc s, tr s, tc s, s);}

}

Void Outputboard (int size)

{

For (int i = 0; i

For (int J = 0; j

COUT << SETW (5) << Board [i] [j];

Cout << Endl;

}

}

This expression (see Example 2 - 2 0) can be calculated by iterative method, and T (k) = (4K) = (the number of three grades required). Since the time you have to take at least (1), you can't get a score and the algorithm of the algorithm is faster.

Reprinted from Shada Studio

转载请注明原文地址:https://www.9cbs.com/read-108015.html

New Post(0)