zoukankan      html  css  js  c++  java
  • bzoj 1923: [Sdoi2010]外星千足虫

    题目链接

    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
    ",ans);
        for(int i = 1;i <= n;++ i) {
            if(a[i][n + 1]) puts("?y7M#");
            else puts("Earth");
        }
        return 0;
    }
    
  • 相关阅读:
    直接插入排序
    直接选择排序
    冒泡排序
    归并排序
    进程调度
    进程与线程
    c语言struct和c++struct的区别
    二叉搜索树、AVL平衡二叉搜索树、红黑树、多路查找树

    6-11 先序输出叶结点
  • 原文地址:https://www.cnblogs.com/sssy/p/8687060.html
Copyright © 2011-2022 走看看