zoukankan      html  css  js  c++  java
  • [bzoj1923]外星千足虫[高斯消元]

    高斯消元解异或方程组

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <cmath>
     7 #include <ctime>
     8 #include <bitset>
     9 
    10 using namespace std;
    11 
    12 int n,m,Ans;
    13 char    str[1100];
    14 bitset<1100>  a[2100];
    15 
    16 void    Gauss()
    17 {
    18     int i,j,k,cur=0;
    19     for(i=1;i<=n;++i)
    20     {
    21         cur++;j=cur;
    22         while(!a[j][i] && j<=m)j++;
    23         if(j==m+1){Ans=-1;return ;}
    24         else    Ans=max(Ans,j);
    25         if(j!=cur)swap(a[j],a[cur]);
    26         for(k=1;k<=m;++k)
    27             if(a[k][i] && k!=cur)a[k]^=a[cur];
    28     }
    29     return ;
    30 }
    31 
    32 int main()
    33 {
    34     int i,j;
    35 
    36     scanf("%d%d",&n,&m);
    37     for(i=1;i<=m;++i)
    38     {
    39         scanf("%s",str+1);
    40         for(j=1;j<=n;++j)a[i][j]=str[j]-48;
    41         scanf("%s",str+1);
    42         a[i][n+1]=str[1]-48;
    43     }
    44 
    45     Gauss();
    46 
    47     if(Ans==-1){printf("Cannot Determine
    ");goto End;}
    48     printf("%d
    ",Ans);
    49     for(i=1;i<=n;++i)
    50         printf("%s
    ",a[i][n+1]?"?y7M#":"Earth");
    51 End:
    52     return 0;
    53 }
  • 相关阅读:
    07 selenium模块基本使用
    06 高性能异步爬虫
    05 request高级操作
    04 验证码识别
    03 数据解析
    02 requests模块
    01 爬虫简介
    Get和Post的正解
    pytoch之 encoder,decoder
    pytorch之 RNN 参数解释
  • 原文地址:https://www.cnblogs.com/Gster/p/5090520.html
Copyright © 2011-2022 走看看