40分求助,2个re,1个wa
查看原帖
40分求助,2个re,1个wa
377902
kc0205楼主2022/11/20 15:44
#include<iostream>

using namespace std;

int n,m,k,x,y;
int a[25][25];

int main(){

    cin >> n >> m >> k;
    for(int i = 1;i <= m;i++){
        cin >> x >> y;
        a[x][y] = 1;
        for(int j = max(x - 2,1);j <= min(x + 2,n);j++){
            a[j][y] = 1;
        }
        for(int j = max(y - 2,1);j <= min(y + 2,n);j++){
            a[x][j] = 1;
        }
        a[max(x - 1,1)][max(y - 1,1)] = 1;
        a[max(x - 1,1)][max(y + 1,1)] = 1;
        a[max(x + 1,1)][max(y + 1,1)] = 1;
        a[max(x + 1,1)][max(y - 1,1)] = 1;
    }
    for(int i = 1;i <= k;i++){
        cin >> x >> y;
        for(int j = max(x - 2,1);j <= min(x + 2,n);j++){
            for(int k = max(y - 2,1);k <= min(y + 2,n);k++){
                a[i][k] = 1;
            }
        }
    }
    int cnt = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
                if(!a[i][j]){
                    cnt++;
                }
            //cout << a[i][j] << " ";
        }
        //cout << endl;
    }
    cout << cnt;

    return 0;
}
/*
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0
0 0 1 0 0
*/
2022/11/20 15:44
加载中...