#include<iostream>
using namespace std;
int num;
int n;
int box[100][100];
void chessBoard(int x/*左上角的位置*/,
int y/*左上角的位置*/,int x1/*骨牌的位置*/,int y1/*骨牌的位置*/,
int length/*棋盘的边长*/)
{
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<box[i][j]<<" ";
}
cout<<endl;
}
if(length==1){
return;
}
int length1=length/2;
num++;
if(x1<x+length1&&y1<y+length1){
// 骨牌在第二象限
chessBoard(x,y,x1,y1,length1);
}else{
box[x+length1-1][y+length1-1]=1;
chessBoard(x,y,x+length1-1,y+length1-1,length1);
}
if(x1<x+length1&&y1>=y+length1){
// 骨牌在第三象限
chessBoard(x,y,x1,y1,length1);
}else{
box[x+length1-1][y+length1]=1;
chessBoard(x,y,x+length1-1,y+length1,length1);
}
if(x1>=x+length1&&y1>=y+length1){
// 骨牌在第四象限
chessBoard(x,y,x1,y1,length1);
}else{
box[x+length1][y+length1]=1;
chessBoard(x,y,x+length1,y+length1,length1);
}
if(x1>=x+length1&&y1<y+length1){
// 骨牌在第一象限
chessBoard(x,y,x1,y1,length1);
}else{
box[x+length1][y+length1-1]=1;
chessBoard(x,y,x+length1,y+length1-1,length1);
}
}
int main()
{
int x1,y1;
cin>>n;
n=1<<n;
cin>>x1>>y1;
box[x1][y1]=1;
chessBoard(0,0,x1,y1,n);
cout<<num;
}
其实这个问题的解决方式也比较简单