bzoj 1923: [Sdoi2010]外星千足虫
题目链接
题解
高斯消元解xor方程
代码
#include<cstdio>
#include<bitset>
#include<cstring>
#include<algorithm>
using std::max;
using std::min;
using std::bitset;
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0'||c > '9'){if(c=='-')f = -1;c = getchar();}
while(c <= '9'&&c >= '0') x = x*10 + c-'0',c = getchar();
return x * f;
}
const int maxn = 1007;
bitset<maxn>a[maxn*2];
int n,m,ans;
char s[maxn];
void Guass() {
int now = 1;
for(int i = 1;i <= n;++ i) {
int j = now;
while(j <= m&&!a[j][i]) j ++;
if(j == m + 1) {ans = -1;break;}
else ans = max(ans,j);
swap(a[now],a[j]);
for(int k = 1;k <= m;++ k)
if(k != now&&a[k][i]) a[k] ^= a[now];
now++;
}
}
int main() {
n = read(),m = read();
for(int X,i = 1;i <= m;++ i) {
scanf("%s",s + 1);
for(int j = 1;j <= n;++ j) a[i][j]=s[j] - '0';
a[i][n+1] = read();
}
Guass();
if(ans == -1) { puts("Cannot Determine"); return 0;}
printf("%d\n",ans);
for(int i = 1;i <= n;++ i) {
if(a[i][n + 1]) puts("?y7M#");
else puts("Earth");
}
return 0;
}