20 分求调
查看原帖
20 分求调
1560058
Albert_Peng楼主2025/6/26 14:40

代码:

#include <iostream>
using namespace std;

void optimise () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

void fill_torch (int x, int y, int &count, bool tab[109][109]) {
    if (!tab[x - 1][y - 1]) {
        count++;
        tab[x - 1][y - 1] = true;
    }
    for (int i = 1; i <= 2; i++) {
        if (!tab[x - i][y] and !tab[x + i][y]) {
            count += 2;
            tab[x - i][y] = true;
            tab[x + i][y] = true;
        }
        if (!tab[x][y - i] and !tab[x][y + i]) {
            count += 2;
            tab[x][y - i] = true;
            tab[x][y + i] = true;
        }
        if (!tab[x - i][y - i] and !tab[x + i][y + i]) {
            count += 4;
            tab[x - i][y - i] = true;
            tab[x + i][y + i] = true;
            tab[x - i][y + i] = true;
            tab[x + i][y - i] = true;
        }
    }
}

void fill_glowstone (int o, int p, int &count, bool tab[109][109]) {
    for (int i = o - 2; i <= o + 2; i++)
        for (int j = p - 2; j <= p + 2; j++)
            if (i >= 0 and j >= 0 and !tab[i][j]) {
                count++;
                tab[i][j] = true;
            }
}

int main () {
    bool tab[109][109] = {};
    int cnt = 0, k, m, n;
    optimise();

    cin >> n >> m >> k;

    for (int i = 0, x, y; i < m; i++) {
        cin >> x >> y;
        fill_torch(x, y, cnt, tab);
    }

    for (int i = 0, o, p; i < k; i++) {
        cin >> o >> p;
        fill_glowstone(o, p, cnt, tab);
    }

    cout << n * n - cnt;

    return 0;
}
2025/6/26 14:40
加载中...