"Gaussian elimination solution xor equation" bzoj1923-[sdoi2010 "Alien thousand Foot Worm

Source: Internet
Author: User
Tags bitset

"The main topic"

There are n number or odd or even, now do m operations, each fetch part sum, tell you the number of operations selected and their parity. If the parity of all the numbers can be obtained by this m operation, the output can be answered at nth times, otherwise the output cannot be determined.

Ideas

In order to solve the XOR equations, the Gaussian elimination element can not determine the minimum number of equations or judgments.

Can not be determined that there is a free element, in each operation to find 1 when the judgment is good; the minimum number of equations is to record the minimum 1 of each found position, the final output maximum.

Error

Forget to change ans to-1 (see Program notes)

Notes

P.s. I see others in the Gaussian elimination process is the current row and all rows XOR again, instead of starting from the next line, and then the result does not need to return to the output of only the n+1 column can be?? It's not for you, okay????

Find the answer in Mo Tao and Proverbs:

Considering the coefficient matrix, each row is an equation, each column is an unknown coefficient in each equation (all coefficients of the equation in line I are pressed to a number a[i], can be used Bitset).
We analyze the condition of the coefficients of each equation after the elimination of the element:
Since we choose the largest one a[i], and find 1 of its highest position, all other equations ( including the equation above the current row ) are all eliminated, that is, for each equation, its coefficient a[i] the highest 1 of the top of the column, only this one 1, The rest is 0. Further, if the number of equations n enough, then the coefficient matrix after the elimination of each row is only one 1, and this 1 is the same column only has this one 1.

1 /*the approach of the back-generation*/2 /**************************************************************3 problem:19234 language:c++5 result:accepted6 time:244 Ms7 memory:1556 KB8 ****************************************************************/9  Ten#include <iostream> One#include <cstdio> A#include <cstring> -#include <algorithm> -#include <bitset> the using namespacestd; - Const intmaxn= ++ -; - Const intmaxm= -+ -; -Bitset<maxn>MAP[MAXM]; + intn,m; - inttimes=-1; +   A voidGauss () at { -      for(intI=1; i<=n;i++) -     { -         intt=i; -          for(; T<=m &&!map[t][i];t++); -         if(t>m) in         { -times=-1;//The Times here are Qingcheng-1 to             return; +         } -         if(t!=i) swap (map[i],map[t]); thetimes=Max (times,t); *          for(intj=i+1; j<=m;j++)  $             if(Map[j][i])Panax Notoginsengmap[j]^=Map[i]; -     } the       + } A   the voidInit () + { -scanf"%d%d",&n,&m); $      for(intI=0; i<m;i++) $     { -         CharSTR[MAXN]; -         intMapans; thescanf"%s%d",str,&Mapans); -map[i+1][n+1]=Mapans;Wuyi          for(intj=0; j<n;j++) map[i+1][j+1]=str[j]-'0'; the     } - } Wu   - voidPrint_ans () About { $     if(times==-1) cout<<"cannot determine"<<Endl; -         Else -         { -printf"%d\n", times); A              for(inti=n;i>=1; i--) +                  for(intk=i+1; k<=n;k++) the                     if(Map[i][k]) -                     { $                         inttmp=map[i][n+1]^map[k][n+1]; themap[i][n+1]=tmp; the                     } the              for(intI=1; i<=n;i++) thePuts ((map[i][n+1])?"? y7m#":"Earth"); -         } in } the   the intMain () About { the init (); the Gauss (); the Print_ans (); +}

The forehead is slowing down ... As if to be cheated of feelings ... Who's going to tell me??!!

/*the practice of not returning to the generation*//************************************************************** problem:1923 language:c++ result:accepted time:284 Ms memory:1556 kb****************************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<bitset>using namespacestd;Const intmaxn= ++ -;Const intmaxm= -+ -; Bitset<MAXN>MAP[MAXM];intn,m;inttimes=-1; voidGauss () { for(intI=1; i<=n;i++)    {        intt=i;  for(; T<=m &&!map[t][i];t++); if(t>m) { times=-1;//The Times here are Qingcheng-1            return; }        if(t!=i) swap (map[i],map[t]); Times=Max (times,t);  for(intj=1; j<=m;j++)             if(I!=j &&Map[j][i]) map[j]^=Map[i]; }     } voidinit () {scanf ("%d%d",&n,&m);  for(intI=0; i<m;i++)    {        CharSTR[MAXN]; intMapans; scanf ("%s%d",str,&Mapans); Map[i+1][n+1]=Mapans;  for(intj=0; j<n;j++) map[i+1][j+1]=str[j]-'0'; }} voidPrint_ans () {if(times==-1) cout<<"cannot determine"<<Endl; Else{printf ("%d\n", times);  for(intI=1; i<=n;i++) puts ((Map[i][n+1])?"? y7m#":"Earth"); }} intMain () {init ();    Gauss (); Print_ans ();}

"Gaussian elimination solution xor equation" bzoj1923-[sdoi2010 "Alien thousand Foot Worm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.