zoukankan      html  css  js  c++  java
  • BZOJ 1923 SDOI2010 外星千足虫 异或方程组+bitset

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1923

      懒得贴题目了......这就是解一个异或方程组的裸题......

      YY了一下异或方程就没毛病了!

      感受了一下bitset的力量噢噢噢!!!!!!

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<set>
     9 #include<map>
    10 #include<vector>
    11 #include<cctype>
    12 #include<bitset>
    13 using namespace std;
    14 const int maxn=1005;
    15 const int maxm=2005;
    16 
    17 int N,M;
    18 bool b[maxm],x[maxm];
    19 char s[maxn];
    20 bitset<maxn>a[maxm];
    21 
    22 void data_in()
    23 {
    24     scanf("%d%d",&N,&M);
    25     for(int i=1;i<=M;i++){
    26         scanf("%s",s+1);
    27         for(int j=1;j<=N;j++) a[i][j]=s[j]-'0';
    28         scanf("%s",s+1);
    29         b[i]=s[1]-'0';
    30     }
    31 }
    32 int Gauss()
    33 {
    34     int i=1,j=1,re=0;
    35     while(i<=M&&j<=N){
    36         re=max(re,i);
    37         if(!a[i][j]){
    38             int tmp=0;
    39             for(int r=i+1;r<=M;r++)
    40                 if(a[r][j]) { tmp=r; break; }
    41             if(!tmp) return 0;
    42             re=max(re,tmp);
    43             swap(a[i],a[tmp]); swap(b[i],b[tmp]);
    44         }
    45         for(int r=i+1;r<=M;r++){
    46             if(!a[r][j]) continue;
    47             a[r]^=a[i],b[r]^=b[i];
    48         }
    49         i++,j++;
    50     }
    51     if(j<=N) return 0;
    52     for(int r=N;r>=1;r--){
    53         x[r]=b[r];
    54         for(int rr=r-1;rr>=1;rr--)
    55             b[rr]^=1*a[rr][r]*x[r];
    56     }
    57     return re;
    58 }
    59 void work()
    60 {
    61     int ans=0;
    62     if(ans=Gauss()){
    63         printf("%d
    ",ans);
    64         for(int i=1;i<=N;i++)
    65             puts(x[i]?"?y7M#":"Earth");
    66     }
    67     else puts("Cannot Determine");
    68 }
    69 int main()
    70 {
    71     data_in();
    72     work();
    73     return 0;
    74 }
    View Code
  • 相关阅读:
    sql的reader方法注意事项
    C++ pair(对组)的简单了解
    cin>>
    枚举
    FirstTry_HelloWorld
    错误:'class QApplication' has no member named 'setMainwidget'
    Open Asset Import Library(assimp) vs2010编译
    vs2010中配置OpenGL以及针对64位系统所遇问题的解决办法
    修改文件夹权限以及右键终端设置
    ubuntu中安装iso文件
  • 原文地址:https://www.cnblogs.com/KKKorange/p/8624863.html
Copyright © 2011-2022 走看看