题目出处:http://codeforces.com/contest/1016/problem/D
#include<iostream> #define ll long long int #define inf 0x3f3f3f3f #define N 1005 using namespace std; ll a[N],b[N]; ll xn[N][N]; ll n,m; int main(){ /**/ cin>>n>>m; ll x = 0; for(int i=0;i<n;i++){ cin>>a[i]; x=x^a[i]; } ll y = 0; for(int i=0;i<m;i++){ cin>>b[i]; y=y^b[i]; } if(x==y){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; return 0; } x = x^a[0]; x = x^b[0]; xn[0][0] = x; for(int i=1;i<m;i++) xn[0][i] = b[i]; for(int i = 1;i<n;i++){ xn[i][0] = a[i]; } for(int i=0;i<n;i++){ for(int j = 0;j<m;j++){ cout<<xn[i][j]<<" "; } cout<<endl; } return 0; }
要使得矩阵存在,那么行和列的异或一定等于零.,或者说行的异或和等于列的异或和.,之后就直接特性的填充。