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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值