【BZOJ1923】【SDOI2010】外星千足虫(线性基,高斯消元)

Description

pic


Solution

考虑将每一次计算结果插入线性基,线性基实质上是一个高斯消元的过程,每次异或时将计算结果同时异或即可。


Code

/************************************************
 * Au: Hany01
 * Date: May 31st, 2018
 * Prob: [BZOJ1923][SDOI2010] 外星千足虫
 * Email: [email protected]
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read()
{
    register int _, __; register char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 1005, maxm = 2005;

bitset<maxn> a[maxm], ne;
int b[maxm], as, n, m, cnt;
char s[maxm];

int main()
{
#ifdef hany01
    File("bzoj1923");
#endif

    n = read(), m = read();
    For(i, 1, m)
    {
        scanf("%s", s), as = read();
        rep(j, n) ne[j] = s[j] & 1;
        Fordown(j, n - 1, 0) if (ne[j])
            if (!a[j][j]) { a[j] = ne, b[j] = as, ++ cnt; break; }
            else ne ^= a[j], as ^= b[j];
        if (cnt == n) { printf("%d\n", i); break; }
    }
    if (cnt < n) puts("Cannot Determine");
    else
        rep(i, n)
            if (b[i]) {
                For(j, i + 1, n - 1)
                    if (a[j][i]) a[j] ^= a[i], b[j] ^= b[i];
                puts("?y7M#");
            } else puts("Earth");

    return 0;
}
//若耶溪傍采莲女,笑隔荷花共人语。
//    -- 李白《采莲曲》

猜你喜欢

转载自blog.csdn.net/hhaannyyii/article/details/80518935