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 ...
随机推荐
- 破损的键盘(codevs 4650)
题目描述 Description 有一天,你需要打一份文件,但是你的键盘坏了,上面的"home"键和"end"键会时不时地按下,而你却毫不知情,甚至你都懒得打开 ...
- Linux下汇编语言学习笔记64 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- scp远程文件传输
第一次.提示下载公钥 [root@rhel5 ~]# scp install.log root@192.168.124.129:/tmp The authenticity of host '192.1 ...
- 获取webview的截图
设置webview可以获取截图: webView.setDrawingCacheEnabled(true); 当要进行多次截图时,先要清除之前的缓存: webview.setDrawingCacheE ...
- 交互设计:隐藏或显示大段文本的UI组件有哪些?
应用场景: 在手机上要给列表中的每一项添加一个大段的介绍,应该用什么UI组件 A: 这里可以用,模态对话框,弹出提示,工具提示这类组件.模态对话框的好处,就是用关闭的按钮,用户操作方便:而弹出提示和工 ...
- Delphi:校验手机号及身份证号
//校验手机号 function IsMobileNumber( num:string ):boolean; begin Result:=False; if length( tr ...
- js获取上传的文件名称
<input name="file_" type="file" id="file_" size="100" /&g ...
- ThinkPHP3.2 点击看不清刷新验证码
欢迎使用Markdown编辑器写博客 baidu了一下.发现没有可用的源码,自己想了想,以下的方法可行. <!DOCTYPE html> <html> <head> ...
- SQL Server 海量数据查询代码优化以及建议
1.应尽量避免在 where 子句中对字段进行 null 值推断,否则将导致引擎放弃使用索引而进 行全表扫描,如: select id from t where num is nu ...
- Jenkins performance插件生成性能测试报告【待完成】
https://segmentfault.com/a/1190000018651092 本地window运行 命令执行:F:\study\apache-jmeter-4.0\apache-jmeter ...