题面
解法
学习了怎么用高斯消元解一个异或方程组
其实和普通的高斯消元是一样的
在多少个方程后就确定答案可以直接边做边取max即可
用bitset优化异或
时间复杂度:\(O(\frac{nm^2}{w})\)
代码
#include <bits/stdc++.h>
using namespace std;
template <typename node> void chkmax(node &x, node y) {x = max(x, y);}
template <typename node> void chkmin(node &x, node y) {x = min(x, y);}
template <typename node> void read(node &x) {
x = 0; int f = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x *= f;
}
int n, m;
bitset <1010> a[2010];
int gauss() {
int now = 0, ret = 0;
for (int i = 1; i <= n; i++) {
int j = now + 1;
while (!a[j][i] && j <= m) j++;
if (j == m + 1) return -1;
chkmax(ret, j);
swap(a[++now], a[j]);
for (int k = 1; k <= m; k++)
if (k != now && a[k][i]) a[k] ^= a[now];
}
return ret;
}
int main() {
read(n), read(m);
for (int i = 1; i <= m; i++) {
char c = getchar();
while (!isdigit(c)) c = getchar();
for (int j = 1; j <= n; j++)
a[i][j] = c - '0', c = getchar();
int t; read(t); a[i][n + 1] = t;
}
int t = gauss();
if (t == -1) return cout << "Cannot Determine\n", 0;
cout << t << "\n";
for (int i = 1; i <= n; i++)
if (a[i][n + 1]) cout << "?y7M#\n";
else cout << "Earth\n";
return 0;
}