标签:org using for class data std can 覆盖 void
#include <cstdio>
#include <iostream>
using namespace std;
int a[1024][1024];
int cnt = 0;
int n, kr, kc;
void solve(int k, int r, int c, int x, int y) {
if (k == 0)
return;
int num = ++cnt;
int midx = x + (1<<k-1), midy = y + (1<<k-1);
int flag;
if (r < midx && c < midy) flag = 1; //左上角
if (r < midx && c >= midy) flag = 2; //右上角
if (r >= midx && c < midy) flag = 3; //左下角
if (r >= midx && c >= midy) flag = 4; //右下角
if (flag == 1)
solve(k-1, r, c, x, y);
else {
a[midx-1][midy-1] = num;
solve(k-1, midx-1, midy-1, x, y);
}
if (flag == 2)
solve(k-1, r, c, x, midy);
else {
a[midx-1][midy] = num;
solve(k-1, midx-1, midy, x, midy);
}
if (flag == 3)
solve(k-1, r, c, midx, y);
else {
a[midx][midy-1] = num;
solve(k-1, midx, midy-1, midx, y);
}
if (flag == 4)
solve(k-1, r, c, midx, midy);
else {
a[midx][midy] = num;
solve(k-1, midx, midy, midx, midy);
}
}
int main() {
scanf("%d%d%d", &n, &kr, &kc);
a[kr-1][kc-1] = -1;
solve(n, kr-1, kc-1, 0, 0);
for (int i = 0; i < (1<<n); i++) {
for (int j = 0; j < (1<<n)-1; j++)
printf("%d ", a[i][j]);
printf("%d\n", a[i][(1<<n)-1]);
}
}
标签:org using for class data std can 覆盖 void
原文地址:https://www.cnblogs.com/baoyihan/p/11068519.html