#include <stdio.h>
#include <string.h>
int t, n, x, y;
bool a[38][38], p;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n), memset(a, 0, sizeof(a)), a[1][1] = p = x = y = 1;
while (p) {
p = 0;
while (a[x + 1][y + 1] != 1 && a[x + 1][y] != 1 && a[x + 2][y] != 1 && x < n) a[++x][y] = 1, p = 1;
while (a[x - 1][y + 1] != 1 && a[x][y + 1] != 1 && a[x][y + 2] != 1 && y < n) a[x][++y] = 1, p = 1;
while (a[x - 1][y - 1] != 1 && a[x - 1][y] != 1 && a[x - 2][y] != 1 && x > 1) a[--x][y] = 1, p = 1;
while (a[x + 1][y - 1] != 1 && a[x][y - 1] != 1 && a[x][y - 2] != 1 && y > 1) a[x][--y] = 1, p = 1;
}
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= n; i++) putchar(a[i][j] ? 35 : 32);
putchar(10);
}
}
return 0;
}题解:[ICPC 2017 Qingdao R] The Squared Mosquito Coil
这是 2026年7月12日 存档的第 1 版,不是当前版本。查看当前版本