算法与算法设计 棋盘覆盖问题

时间:2011-11-20 07:01:28
【文件属性】:

文件名称:算法与算法设计 棋盘覆盖问题

文件大小:46KB

文件格式:DOC

更新时间:2011-11-20 07:01:28

棋盘覆盖,算法

主要代码清单: #include "stdio.h" #include "conio.h" int board[8][8] ={ {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0} }; int tile=0; void chessBoard(int tr, int tc, int dr, int dc, int size) { int t=tile++, s=size/2; if (size==1) return; if (dr= tc+s) chessBoard(tr,tc+s,dr,dc,s); else { board[tr+s-1][tc+s]=t; chessBoard(tr,tc+s,tr+s-1,tc+s,s);} if(dr >= tr+s&&dc= tr+s &&dc>=tc+s) chessBoard(tr+s,tc+s,dr,dc,s); else { board[tr+s][tc+s]=t; chessBoard(tr+s,tc+s,tr+s,tc+s,s);} } main() { int i ,j; chessBoard(0,0,5,5,8); for(i=0;i <8;i++) { for( j=0;j <8;j++) { if(board[i][j]<10) printf("0"); printf("%d",board[i][j]); printf(" "); } printf( "\n"); } getchar(); }


网友评论