題目出處:http://codeforces.com/contest/1016/problem/Dios
#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; }
要使得矩陣存在,那麼行和列的異或必定等於零.,或者說行的異或和等於列的異或和.,以後就直接特性的填充。ide