#include "iostream"
#include "algorithm"
using namespace std;
#define MAX 100
int map[MAX][MAX];
int n, position_x, position_y, ncount;
void Search(int up, int down, int left, int right, int special_x, int special_y) {
if (down - up >= 3 || right - left >= 3) {
int mid_height = (up + down) / 2;
int mid_width = (left + right) / 2;
if (mid_height >= special_x && mid_width >= special_y) {
ncount++;
map[mid_height + 1][mid_width] = ncount;
map[mid_height + 1][mid_width + 1] = ncount;
map[mid_height][mid_width + 1] = ncount;
Search(up, mid_height, left, mid_width, special_x, special_y);
Search(mid_height + 1, down, left, mid_width, mid_height + 1, mid_width);
Search(up, mid_height, mid_width + 1, right, mid_height, mid_width + 1);
Search(mid_height + 1, down, mid_width + 1, right, mid_height + 1, mid_width + 1);
} else if (mid_height >= special_x && mid_width < special_y) {
ncount++;
map[mid_height][mid_width] = ncount;
map[mid_height + 1][mid_width + 1] = ncount;
map[mid_height + 1][mid_width] = ncount;
Search(up, mid_height, mid_width + 1, right, special_x, special_y);
Search(up, mid_height, left, mid_width, mid_height, mid_width);
Search(mid_height + 1, down, left, mid_width, mid_height + 1, mid_width);
Search(mid_height + 1, down, mid_width + 1, right, mid_height + 1, mid_width + 1);
} else if (mid_height < special_x && mid_width >= special_y) {
ncount++;
map[mid_height][mid_width] = ncount;
map[mid_height + 1][mid_width + 1] = ncount;
map[mid_height][mid_width + 1] = ncount;
Search(mid_height + 1, down, left, mid_width, special_x, special_y);
Search(up, mid_height, mid_width + 1, right, mid_height, mid_width + 1);
Search(up, mid_height, left, mid_width, mid_height, mid_width);
Search(mid_height + 1, down, mid_width + 1, right, mid_height + 1, mid_width + 1);
} else if (mid_height < special_x && mid_width < special_y) {
ncount++;
map[mid_height + 1][mid_width] = ncount;
map[mid_height][mid_width] = ncount;
map[mid_height][mid_width + 1] = ncount;
Search(mid_height + 1, down, mid_width + 1, right, special_x, special_y);
Search(up, mid_height, mid_width + 1, right, mid_height, mid_width + 1);
Search(up, mid_height, left, mid_width, mid_width, mid_height);
Search(mid_height + 1, down, left, mid_width, mid_height + 1, mid_width);
}
} else {
ncount++;
for (int i = up; i <= down; i++) {
for (int j = left; j <= right; j++) {
if (i == special_x && j == special_y) {
continue;
} else {
map[i][j] = ncount;
}
}
}
return ;
}
}
int main() {
cin >> n >> position_x >> position_y;
if (position_x < 0 || position_y < 0 || position_x >= n || position_y >= n || n % 2 != 0) {
cout << "Informal Input" << endl;
return 1;
}
Search(0, n - 1, 0, n - 1, position_x, position_y);
if (!ncount) {
cout << "Informal input or can't be solved!" << endl;
} else {
cout << ncount << " is needed!" << endl;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%4d", map[i][j]);
}
cout << endl;
}
return 0;
}
文章评论