The solution to the Board coverage problem is written in C language, so that you can take it later.
/**//*
* ===================================================== ============================================
*
* Filename: chess_board.c
*
* Description: the solution of chess board's coverage
*
* Version: 1.0
* Created: 09/16/06 22:37:43 CST
* Revision: None
* Compiler: gcc
*
* Author: LiRui (Colin), lirui@ncic.ac.cn
* Company: asl.ncic.ac.cn
*
* ===================================================== ============================================
*/
# Include <stdio. h>
# Define maxsize 1 <10
Int chess [maxsize] [maxsize];
Void chess_board (int tr, int TC, int DR, int DC, int size)
...{
Static int tile = 1;
If (1 = size) return;
Int T = tile ++;
Int S = (size> 1 );
/** // * ---- Left-up corner ----*/
If (Dr <tr + S & DC <TC + S )...{
Chess_board (TR, TC, Dr, DC, S );
} Else ...{
Chess [tr + s-1] [TC + s-1] = T;
Chess_board (TR, TC, tr + s-1, TC + s-1, S );
}
/** // * ---- Right-up corner ---*/
If (Dr <tr + S & DC> = TC + S )...{
Chess_board (TR, TC + S, Dr, DC, S );
} Else ...{
Chess [tr + s-1] [TC + S] = T;
Chess_board (TR, TC + S, tr + s-1, TC + S, S );
}
/** // * ---- Left-down corner ---*/
If (Dr> = tr + S & DC <TC + S )...{
Chess_board (tr + S, TC, Dr, DC, S );
} Else ...{
Chess [tr + S] [TC + s-1] = T;
Chess_board (tr + S, TC, tr + S, TC + s-1, S );
}
/** // * ---- Right-down corner --*/
If (Dr> = tr + S & DC> = TC + S )...{
Chess_board (tr + S, TC + S, Dr, DC, S );
} Else ...{
Chess [tr + S] [TC + S] = T;
Chess_board (tr + S, TC + S, tr + S, TC + S, S );
}
}
Void print_chess (INT size)
...{
Int I, J;
For (I = 0; I <size; I ++ )...{
For (j = 0; j <size; j ++)
Printf ("% 4D", chess [I] [J]);
Printf ("");
}
}
Int main (INT argc, char * argv [])
...{
Chess_board (0, 0, 1, 2, 16 );
Print_chess (16 );
Return 0;
}/** // * ---------- End of function main ----------*/