跳到正文

题解

题解:[ICPC 2017 Qingdao R] The Squared Mosquito Coil

Rated约 2 分钟
原文

这是 2026年7月12日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年7月12日
收录
2026年7月12日
更新
2026年11月14日
篇幅
约 2 分钟
获赞
1
题目
P17100

版本

  1. v2当前
  2. v1
C++
#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;
}