欢迎来到 xht37 的博客

CF1119C Ramesses and Corner Inversion

题目地址:CF1119C Ramesses and Corner Inversion

将两个矩阵异或起来,为 \(1\) 的位置就是需要修改的位置

注意到每一次操作都会导致两行和两列上有两个数被修改

那么如果有一行或一列上只有一个需要被修改的数,显然不可能

否则即可能

#include <bits/stdc++.h>
using namespace std;
const int N = 506;
int n, m, a[N][N], b[N][N];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", &b[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            a[i][j] ^= b[i][j];
    for (int i = 1; i <= n; i++) {
        int o = 0;
        for (int j = 1; j <= m; j++)
            o ^= a[i][j];
        if (o) {
            puts("No");
            return 0;
        }
    }
    for (int j = 1; j <= m; j++) {
        int o = 0;
        for (int i = 1; i <= n; i++)
            o ^= a[i][j];
        if (o) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}
posted @ 2019-04-11 00:48 xht37 阅读(...) 评论(...) 编辑 收藏