CCF-CSP 201912-2回收站选址

回收站选址

#include 
using namespace std;

int ans[6];
map , int> g;//垃圾的位置
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        int x, y;
        scanf("%d%d", &x, &y);
        g[{x, y}] = 1;
    }
    for (auto _ : g){
        int x = _.first.first;
        int y = _.first.second;
        if (g[{x, y}] ==1){
            if (g[{x + 1, y}] == 1 && g[{x, y + 1}] == 1 && g[{x - 1, y}] == 1 && g[{x, y - 1}] == 1){
                int cnt = 0;
                if (g[{x + 1, y + 1}] == 1) cnt++;
                if (g[{x - 1, y - 1}] == 1) cnt++;
                if (g[{x + 1, y - 1}] == 1) cnt++;
                if (g[{x - 1, y + 1}] == 1) cnt++;
                ans[cnt]++;
            }
        }
    }
    for (int i = 0; i < 5; i++){
        printf("%d\n", ans[i]);
    }
    return 0;
}

/*

*/

你可能感兴趣的:(CCF-CSP认证)