首页 > 其他 > 详细

bzoj 1923 [Sdoi2010]外星千足虫 高斯消元

时间:2018-08-14 19:21:54      阅读:171      评论:0      收藏:0      [点我收藏+]

题面

题目传送门

解法

学习了怎么用高斯消元解一个异或方程组

其实和普通的高斯消元是一样的

在多少个方程后就确定答案可以直接边做边取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;
}

bzoj 1923 [Sdoi2010]外星千足虫 高斯消元

原文:https://www.cnblogs.com/copperoxide/p/9476733.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!