AcWing 5396. 棋盘
原题链接
简单
作者:
小王子_19
,
2024-03-30 17:34:41
,
所有人可见
,
阅读 1
C++ 代码 最开始做的时候,没有考虑奇偶问题,还是得想得全面些
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2010;
int a[N][N];
int n, m;
int main()
{
cin >> n >> m;
while (m -- )
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
a[x1][y1] += 1, a[x2 + 1][y2 + 1] += 1;
a[x1][y2 + 1] -= 1, a[x2 + 1][y1] -= 1;
}
for (int i = 1; i <= n; i ++ )
{
for (int j = 1; j <= n; j ++ )
{
a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
if (a[i][j] % 2 == 0)
printf("%d", 0);
else printf("%d", 1);
}
puts("");
}
return 0;
}