要求构造n行m列的矩阵,使得每一行的数值异或结果分别为(a_i),每一列的数值异或结果分别为(b_i)。
解:第一行为(b_1,b_2...b_m)第一列为(a_1,a_2,...a_n)最后将左上角修改为(a_1oplus b_2 oplus b_3 ... oplus b_m)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int n, m;
const int maxn = 1e2 + 10;
int A[maxn], B[maxn];
int ans[maxn][maxn];
int r1, r2;
int main() {
scanf("%d%d", &n, &m);
r1 = 0; r2 = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
r1 ^= A[i];
}
for (int i = 0; i < m; i++) {
scanf("%d", &B[i]);
r2 ^= B[i];
}
if (r1 != r2) {
puts("NO");
} else {
int t = 0;
for (int i = 1; i < m; i++) ans[0][i] = B[i], t ^= B[i];
for (int i = 1; i < n; i++) ans[i][0] = A[i];
ans[0][0] = (t ^ A[0]);
puts("YES");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%d%c", ans[i][j], j == m - 1 ? '
' : ' ');
}
}
}
return 0;
}