D. Vasya And The Matrix(Educational Codeforces Round 48)
D. Vasya And The Matrix
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!
Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence a1, a2, ..., an denotes the xor of elements in rows with indices 1, 2, ..., n, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence b1, b2, ..., bm denotes the xor of elements in columns with indices 1, 2, ..., m, respectively.
Help Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.
Input
The first line contains two numbers n and m (2 ≤ n, m ≤ 100) — the dimensions of the matrix.
The second line contains n numbers a1, a2, ..., an (0 ≤ ai ≤ 109), where ai is the xor of all elements in row i.
The third line contains m numbers b1, b2, ..., bm (0 ≤ bi ≤ 109), where bi is the xor of all elements in column i.
Output
If there is no matrix satisfying the given constraints in the first line, output "NO".
Otherwise, on the first line output "YES", and then n rows of m numbers in each ci1, ci2, ... , cim (0 ≤ cij ≤ 2·109) — the description of the matrix.
If there are several suitable matrices, it is allowed to print any of them.
直接构造一个任意的(n-1)*(m-1)的0矩阵,最后一个值异或得到
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
int n, m;
int r, c;
int a[105], b[105];
cin >> n >> m;
r = c = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
r ^= a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
c ^= b[i];
}
if (r != c) {
puts("NO");
} else {
bool first;
puts("YES");
for (int i = 0; i < n; i++) {
first = true;
for (int j = 0; j < m; j++) {
if (!first) printf(" ");
else first = false;
if (i != n-1 && j != m-1) {
printf("0");
} else if (j == m-1 && i == n-1) {
r = 0;
for (int k = 0; k < m-1; k++) r ^= b[k];
r ^= a[n-1];
printf("%d", r);
} else if (j == m-1){
printf("%d", a[i]);
} else {
printf("%d", b[j]);
}
}
printf("\n");
}
}
return 0;
}
D. Vasya And The Matrix(Educational Codeforces Round 48)的更多相关文章
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 48
题目地址 Edu48 A.Death Note 翻译 你有一个无穷页的本子,每一页可以写\(m\)个名字, 你在第\(i\)天要写\(a_i\)个名字,如果这一页恰好写满了,你就会翻页, 问每天的翻页 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
[链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...
- Educational Codeforces Round 48 D Vasya And The Matrix
EDU #48 D 题意:给定一个矩阵,已知每一行和每一列上数字的异或和,问矩阵上的数字是多少,不存在则输出NO. 思路:构造题,可以考虑只填最后一行,和最后一列,其中(n,m)要特判一下.其他格子给 ...
- Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))
A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- Educational Codeforces Round 48 (Rated for Div. 2)
http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法 为什么我做了那么多讨论,原 ...
- Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)
B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- [NOIP2004] 提高组 洛谷P1091 合唱队形
题目描述 N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队形. 合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2…,K,他们的身高分别为T1,T2, ...
- POJ 2686_Traveling by Stagecoach【状态压缩DP】
题意: 一共有m个城市,城市之间有双向路连接,一个人有n张马车票,一张马车票只能走一条路,走一条路的时间为这条路的长度除以使用的马车票上规定的马车数,问这个人从a出发到b最少使用时间. 分析: 状态压 ...
- java.lang.RuntimeException: JPedal Trial has now expired
具体提示: java.lang.RuntimeException: JPedal Trial has now expired jpedal-server-trial.jar jar包过期了,jpeda ...
- fuse-dfs挂载hdfs实录
部署安装了最新稳定版hadoop2.2.0.然后在网上找来fuse-dfs编译教程.可是最后失败了.至今原因未知--,错误描写叙述为:Transport endpoint is not connect ...
- Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Kafka跨集群同步工具——MirrorMaker
MirrorMaker是为解决Kafka跨集群同步.创建镜像集群而存在的.下图展示了其工作原理.该工具消费源集群消息然后将数据又一次推送到目标集群. watermark/2/text/aHR0cDov ...
- 背包系统学习笔(tu)记(cao)
这几天在学习背包系统,网上有看到一个挺牛逼的背包系统,不过人家那个功能很全面,一个背包系统就囊括了装备,锻造,购买等等功能(这里给出网址:https://blog.csdn.net/say__yes/ ...
- Guake Terminal ── linux下完美帅气的终端
虽说如今非常多Linux发行版.比方Ubuntu,已经基本上能够採用GUI来完毕绝大部分一般性的任务. 可是,终端程序对于linux用户来说仍是不可缺少的. Gnome自带的gnome-termina ...
- pat(A) 1063. Set Similarity(STL)
代码: #include<cstdio> #include<cstring> #include<set> using namespace std; set<i ...
- leetcode第一刷_Search in Rotated Sorted Array
旋转数组的查找问题.从头開始扫一遍.O(N)的复杂度,一般也能过,甚至先排序下面,再二分都能过.只是这道题的目的当然不在于此. 想一下旋转之后对我们的查找产生了什么影响.假设没旋转过,我们直接比較ta ...