3个WA,求助
查看原帖
3个WA,求助
818617
ErXiao楼主2023/2/3 22:46
// P1789.cpp
#include <bits/stdc++.h>
using namespace std;

// 方阵初始状态全为'\0'
char square[100][100] = {'0'};

int main()
{
    // n*n方阵,m为火把个数,k为萤石个数
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x, y;
    while (m--) // 标记火把
    {
        scanf("%d%d", &x, &y);
        // 1.点亮火把2*2方阵
        for (int i = x - 1; i <= x + 1; i++)
            for (int j = y - 1; j <= y + 1; j++)
                if (i >= 1 && i <= n && j >= 1 && j <= n)
                    square[i][j] = 1;
        // 2.点亮5*1
        for (int i = x - 2; i <= x + 2; i++)
            if (i >= 1 && i <= n)
                square[i][y] = 1;
        // 3.点亮1*5
        for (int j = x - 2; j <= x + 2; j++)
            if (j >= 1 && j <= n)
                square[x][j] = 1;
    }
    while (k--) // 标记萤石
    {
        scanf("%d%d", &x, &y);
        for (int i = x - 2; i <= x + 2; i++)
            for (int j = y - 2; j <= y + 2; j++)
                if (i >= 1 && i <= n && j >= 1 && j <= n)
                    square[i][j] = 1;
    }

    // 计算怪物数量
    int monster = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (square[i][j] == '\0')
                monster++;
    printf("%d\n", monster);
    return 0;
}
2023/2/3 22:46
加载中...