Luogu1275 Magic Board

https://zybuluo.com/ysner/note/1136271

topic

There is such a magic board: it is a rectangular panel divided into \(n\) rows and \(m\) columns of \(n*m\) squares. There is a small light bulb in each square, and the light bulb has two states (bright or dark). We can change the magic board from one state to another by several actions. There are two modes of operation:
(1) Select a row to change the status of all bulbs in the row, that is, the bright ones are dimmed, and the dark ones are brighter;
(2) Two columns are selected, and their positions are exchanged.
Your task is to determine whether the two states can be transformed into each other based on the given two magic board states.

Parse

First of all, we can see a property at a glance: there can only be two or one number of light bulbs per row.
(But this is of no use)
Seriously, the status of this question is only \(0\) , \(1\) , \(bitset\) go.
Then I can sort the columns lexicographically since the columns can be swapped arbitrarily.
Then enumerate to see if there is a column that can become the first column of the target state.
In the judgment process, if a row of numbers is different, it will be flipped, and then sorted at the end. If the following columns can be matched one by one, \(yes\) , otherwise continue.
( The core idea is that when simulating, you can only flip a line once, otherwise it will change the previous one when it is flipped back )

int k,n,m,ans;
bitset<105>a[105],b[105],c;
il bool cmp(bitset<105>x,bitset<105>y)
{
  fp(i,1,n) if(x[i]^y[i]) return x[i]<y[i];
  return 0;
}
int main()
{
  //freopen("panel.in","r",stdin);
  //freopen("panel.out","w",stdout);
  k=gi();
  while(k--)
    {
      n=gi();m=gi();ans=0;
      fp(i,1,m) a[i].reset(),b[i].reset();
      fp(i,1,n) fp(j,1,m) a[j][i]=gi();
      fp(i,1,n) fp(j,1,m) b[j][i]=gi();
      sort(a+1,a+1+m,cmp);sort(b+1,b+1+m,cmp);
      fp(i,1,m)
    {
      c=a[i]^b[1];
      fp(j,1,m) a[j]^=c;
      sort(a+1,a+1+m,cmp);
      re int flag=1;
      fp(j,1,m) if(a[j]!=b[j]) {flag=0;break;}
      if(flag) {ans=1;break;}
      fp(j,1,m) a[j]^=c;
      sort(a+1,a+1+m,cmp);
    }
      puts(ans?"YES":"NO");
    }
  fclose(stdin);
  fclose(stdout);
  return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325383664&siteId=291194637