import java.util.Scanner;
public class Main {
static int tile = 1;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int k = sc.nextInt();
int dr = sc.nextInt(); // 特殊方格所在行
int dc = sc.nextInt(); // 特殊方格所在列
int[][] Board = new int[(int) Math.pow(2, k)][(int) Math.pow(2, k)];
Board[dr][dc]=0;
ChessBoard(Board, 0, 0, dr, dc, Board.length);
for (int i = 0; i < Board.length; i++) {
for (int j = 0; j < Board.length; j++) {
System.out.print(Board[i][j] + "\t");
}
System.out.println();
}
}
public static void ChessBoard(int Board[][],int r_0,int c_0,int dr,int dc,int size){
int s;
int t;
if (size==1) return;
t=tile++;
s=size/2;
if (dr<=r_0+s-1 && dc<=c_0+s-1)
ChessBoard(Board,r_0,c_0,dr,dc,s);
else{
Board[r_0+s-1][c_0+s-1]=t;
ChessBoard(Board,r_0,c_0,r_0+s-1,c_0+s-1,s);
}
if (dr<=r_0+s-1 && dc>=c_0+s)
ChessBoard(Board,r_0,c_0+s,dr,dc,s);
else{
Board[r_0+s-1][c_0+s]=t;
ChessBoard(Board,r_0,c_0+s,r_0+s-1,c_0+s,s);
}
if (dr>=r_0+s && dc<c_0+s) //判断特殊方格是否在左下角子棋盘
ChessBoard(Board,r_0+s,c_0,dr,dc,s);
else //用t号骨牌覆盖右上角继续覆盖此子棋盘
{
Board[r_0 + s][c_0 + s - 1] = t;
ChessBoard(Board, r_0 + s, c_0, r_0 + s, c_0 + s - 1, s);
}
if (dr>=r_0+s && dc>=c_0+s) //判断特殊方格是否在右下角子棋盘
ChessBoard(Board,r_0+s,c_0+s,dr,dc,s);
else //用t号骨牌覆盖左上角继续覆盖此子棋盘
{
Board[r_0+s][c_0+s]=t;
ChessBoard(Board,r_0+s,c_0+s,r_0+s,c_0+s,s);
}
}
}
棋盘覆盖 笔记
于 2024-05-07 20:54:40 首次发布