1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream> using namespace std; #define N 1025 int board[N][N]; static int tile = 1;
void ChessBoard(int tr, int tc, int dr, int dc, int size) { if(size == 1) return; int t = tile++; int s = size/2; if(dr < tr + s && dc < tc + s) ChessBoard(tr, tc, dr, dc, s); else { board[tr + s - 1][tc + s - 1] = t; ChessBoard(tr, tc, tr + s - 1, tc + s - 1, s); } if(dr < tr + s && dc >= 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 < tc + s) ChessBoard(tr + s, tc, dr, dc, s); else { board[tr + s][tc + s - 1] = t; ChessBoard(tr + s, tc, tr + s, tc + s - 1, s); } if(dr >= tr + s && dc >= t c+ 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); } }
int main() { int i, j, k, x, y; while(cin >> k) { int size = 1 << k; cin >> x >> y; board[x][y] = 0; ChessBoard(0, 0, x, y, size); for(i = 0; i < size; i++) { for(j = 0; j < size; j++) cout << board[i][j] << '\t'; cout << '\n'; } } return 0; }
|