Bzoj1923: [Sdoi2010]外星千足虫
题面
Sol
显然高斯消元
你会发现线性基和高斯消元本质上好像差不多
直接上线性基判断是否有解
线性基的插入不就是高斯消元吗
然后bitset优化即可
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef long double lod;
template <class Int>
IL void Input(RG Int &x){
RG int z = 1; RG char c = getchar(); x = 0;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= z;
}
const int maxn(1005);
int n, m, num;
bitset <maxn> a[maxn], tmp;
char s[maxn];
IL void Gauss(){
for(RG int i = n; i > 1; --i)
for(RG int j = i - 1; j; --j)
a[j][n + 1] = a[j][n + 1] ^ (a[j][i] & a[i][n + 1]);
for(RG int i = 1; i <= n; ++i)
puts(a[i][n + 1] ? "?y7M#" : "Earth");
exit(0);
}
int main(RG int argc, RG char* argv[]){
Input(n), Input(m);
for(RG int i = 1, k; i <= m; ++i){
scanf(" %s", s + 1), Input(k), tmp[n + 1] = k;
for(RG int j = 1; j <= n; ++j) tmp[j] = s[j] == '1';
for(RG int j = 1; j <= n; ++j)
if(tmp[j]){
if(!a[j][j]){
a[j] = tmp, ++num;
break;
}
tmp = tmp ^ a[j];
}
if(num == n){
printf("%d\n", i);
Gauss();
}
}
puts("Cannot Determine");
return 0;
}