自己试了好多个都过不了
难道是因为和题目编码不一样吗
#include <bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
int n, x, y, idx=0;
int a[1050][1050];
void P(){
for (re int i = 1; i <= 1<<n; i++) {
for (re int j = 1; j <= 1<<n; j++) {
cout << a[i][j] <<' ';
}
cout << '\n';
}
return;
}
void f(int lft, int rgt, int up, int dw, int x,int y) {
int h=lft+rgt>>1,l=up+dw>>1;
int p=(x>h)*2+(y>l);
//0左上,1左下,2右上,3右下
if(p==0) a[h+1][l]=++idx,a[h][l+1]=idx,a[h+1][l+1]=idx;
if(p==1) a[h][l]=++idx,a[h+1][l]=idx,a[h+1][l+1]=idx;
if(p==2) a[h][l]=++idx,a[h+1][l+1]=idx,a[h][l+1]=idx;
if(p==3) a[h][l]=++idx,a[h+1][l]=idx,a[h][l+1]=idx;
if(rgt-lft+1>2){
if(p==0) f(lft,h,up,l,x,y);
else f(lft,h,up,l,h,l);
if(p==1) f(lft,h,l+1,dw,x,y);
else f(lft,h,l+1,dw,h,l+1);
if(p==2) f(h+1,rgt,up,l,x,y);
else f(h+1,rgt,up,l,h+1,l);
if(p==3) f(h+1,rgt,l+1,dw,x,y);
else f(h+1,rgt,l+1,dw,h+1,l+1);
}
return;
}
int main() {
cin >> n >> x >> y;
f(1, 1<<n, 1, 1<<n, x,y);
P();
return 0;
}