存着做模板
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int dir[8][2] = { {-1, -2}, {1, -2}, {-2, -1}, {2, -1}, {-2, 1}, {2, 1}, {-1, 2}, {1, 2} };
int p, q, b[27][27];
struct Map {
int y, x;
}ans[1000];
int judge(int x, int y ) {
if(x <= 0 || x > q || y <= 0 || y > p)
return 0;
return 1;
}
int dfs(int x, int y, int step) {
if(step == p * q) return 1;
int tx, ty;
for(int i = 0; i < 8; i++) {
ty = y + dir[i][0];
tx = x + dir[i][1];
if(judge(tx, ty) && b[tx][ty] == 0) {
ans[step + 1].x = tx;
ans[step + 1].y = ty;
b[tx][ty] = 1;
if(dfs(tx, ty, step + 1))
return 1;
b[tx][ty] = 0;
}
}
return 0;
}
int main() {
//freopen("input.txt", "r", stdin);
int n;
scanf("%d", &n);
for(int j = 1; j <= n; j++) {
memset(ans, 0, sizeof(ans));
memset(b, 0, sizeof(b));
int flag = 1;
scanf("%d%d", &p, &q);
for(int s = 1; s <= q; s++)
for(int t = 1; t <= p; t++) {
ans[1].x = s;
ans[1].y = t;
b[s][t] = 1;
if(dfs(s, t, 1)) {
printf("Scenario #%d:\n", j);
for(int k = 1; k <= p*q; k++)
printf("%c%d", (ans[k].x-1) + 'A', ans[k].y);
printf("\n");
flag = 0;
break;
}
}
if(flag) {
printf("Scenario #%d:\n", j);
printf("impossible\n");
}
putchar('\n');
}
}