80分蒟蒻求助!!
查看原帖
80分蒟蒻求助!!
206430
_tyc楼主2020/8/25 16:32
#include <iostream>
using namespace std;
char a[101][101];
int ans[101][101];
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        a[x][y] = 'h';
    }
    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        a[x][y] = 'y';
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] == 'h') {
                ans[i - 2][j] = 1;
                ans[i + 2][j] = 1;
                for (int s = j - 1; s <= j + 1; s++) {
                    ans[i - 1][s] = 1;
                }
                for (int s = j - 1; s <= j + 1; s++) {
                    ans[i + 1][s] = 1;
                }
                for (int s = j - 2; s <= j + 2; s++) {
                    ans[i][s] = 1;
                }
            }
            if (a[i][j] == 'y') {
                for (int ii = i - 2; ii <= i + 2; ii++) {
                    for (int jj = j - 2; jj <= j + 2; jj++)  {
                        ans[ii][jj] = 1;
                    }
                }
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (!ans[i][j]) {
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}
2020/8/25 16:32
加载中...