CF1016 D. Vasya And The Matrix

传送门

[http://codeforces.com/group/1EzrFFyOc0/contest/1016/problem/D]

题意

已知矩阵n行m列,以及每一行,每一列所有元素的异或,用 a1到an表示行异或值,用b1到bm表示列异或值
让你构造一个矩阵满足上面的要求

思路

整个矩阵所有元素异或值等于a1异或到an,同时等于b1异或到bm,如a1异或到an不等于b1异或到bm,就不能构造该矩阵,输出NO
否则输出YES,并构造该矩阵
左上角元素等于a1异或b2异或到bm,第一行其他元素分别等于b2到bm,第一列其他元素分别等于a2到an。剩下的所有元素都等于0,即可

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[105],b[105];
int main(){
    int n,m,i,j;
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //freopen("in.txt","r",stdin);
    while(cin>>n>>m){
        int ok=0;
        for(i=1;i<=n;i++)
        cin>>a[i],ok^=a[i];
        for(j=1;j<=m;j++)
        cin>>b[j],ok^=b[j];
        if(!ok==0)
        {
            cout<<"NO\n";
        }
        else{
            puts("YES");
        ok=a[1];
        for(i=2;i<=m;i++)
        ok^=b[i];
        cout<<ok<<' ';
        for(i=2;i<=m;i++)
        cout<<b[i]<<' ';
        cout<<endl;
        for(i=2;i<=n;i++)
        {
            cout<<a[i]<<' ';
            for(j=2;j<=m;j++)
            cout<<0<<' ';
            cout<<endl;
        }
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mch5201314/p/9453819.html