AcWing 3371. 舒适的奶牛
原题链接
简单
作者:
蜡笔xx
,
2022-05-10 00:14:40
,
所有人可见
,
阅读 153
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1020;
int n, res;
bool g[N][N];
int cnt[N][N];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
void check(int x, int y){
cnt[x][y]++;
g[x][y] = true;
for(int i = 0; i < 4; i ++){
int xx = x + dx[i], yy = y + dy[i];
cnt[xx][yy]++;
if(g[xx][yy] && cnt[xx][yy] == 4) res++;
if(g[xx][yy] && cnt[xx][yy] == 5) res--;
}
}
int main(){
cin >> n;
while(n --){
int x, y;
cin >> x >> y;
check(x + 10, y + 10); //避免边界问题
cout << res << endl;
}
return 0;
}