Educational Codeforces Round 48 (Rated for Div. 2) XOR thinking

Title: https://codeforces.com/contest/1016/problem/D

The meaning of problems: there is a matrix of n * m, n and now give you the number, the i-th a [i] i represents the number of all the line and Or.

   You give the number m, the number of the i-b [i], i represents the number of all the columns and Or.
   Q. Can you construct a matrix meet any of the conditions, not output NO, YES and that can output matrix.

Analysis: Consider the case of yes and no, yes if and only if, all of the rows is equal to the exclusive OR and exclusive OR and all columns

   The reason: All XOR and x, is the number of all the XOR and the entire array, the column also analyzed y line, so obvious, or maybe has a different and x == y must be the same, the matrix can be constructed.

   Structure: simple, directly to the number of sets in a row, another column in a set, is the simplest, but taking into account the position of the first line intersecting the first column, then only properly handle the crossing position, you can follow this simple method of construction

        Consider the first column, the column except for the first position and the exclusive OR of x ^ a [i], then to achieve this column and XOR == b [i], then this is the only location x ^ a [i ] ^ b [i], then x == y due consideration for exactly the same logic line

 

#include<bits/stdc++.h>
using namespace std;
const int M=110;
int mp[M][M];
int a[M],b[M];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int x=0,y=0;
    for(int i=1;i<=n;i++){
        cin>>a[i],x^=a[i];
    }
    for(int i=1;i<=m;i++)
        cin>>b[i],y^=b[i];
    if(x!=y)
        puts("NO");
    else{
        
        puts("YES");
        x^=a[1];
        x^=b[1];
        mp[1][1]=x;
        for(int i=2;i<=n;i++)
            mp[i][1]=a[i];
        for(int i=2;i<=m;i++)
            mp[1][i]=b[i];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)
                cout<<mp[i][j]<<" ";
            cout<<endl;
        }
    }
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/starve/p/11839277.html