time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

Examples
input

Copy
2 3
2 9
5 3 13
output

Copy
YES
3 4 5
6 7 8
input

Copy
3 3
1 7 6
2 15 12
output

Copy
NO
题意:题意:给出n,m表示有一个n*m的矩阵,然后第一行给出n个数,每个数ai表示第i行所有的数的亦或和,第二行给出m个数,每个数bi表示第i列所有数的亦或和。问,是否可以构造出这样的一个矩阵,如果可以,输出“YES”并且输出这个矩阵,否则,输出“NO”.
分析:这题是迷之构造法,我们只要考虑矩阵最后一列与最后一行便可以了,其他的为0;
#include<stdio.h>
const int maxn = ;
int a[maxn],b[maxn],G[maxn][maxn];
int main( )
{
int n,m,cnt1=,cnt2=;
scanf("%d%d",&n,&m);
for(int i= ; i<=n ; i++)
{
scanf("%d",&a[i]);
} for(int i= ; i<=m ; i++)
{
scanf("%d",&b[i]);
} cnt1=a[],cnt2=b[];
for(int i= ; i<n ; i++)
cnt1^=a[i];
cnt1^=b[m];
for(int i= ; i<m ; i++)
cnt2^=b[i];
cnt2^=a[n];
if(cnt1!=cnt2)
{
puts("NO");
return ;
}
puts("YES");
for(int i= ; i<n ; i++)
for(int j= ; j<m ; j++)
G[i][j]=;
for(int i= ; i<n ; i++)
{
G[i][m]=a[i];
}
for(int i= ; i<m ; i++)
{
G[n][i]=b[i];
}
G[n][m]=cnt1;
for(int i= ; i<=n ;i++)
{
for(int j= ; j<=m ; j++)
printf("%d ",G[i][j]);
puts(" ");
}
return ;
}

codeforces1016 D. Vasya And The Matrix(思维+神奇构造)的更多相关文章

  1. Vasya And The Matrix CodeForces - 1016D (思维+构造)

    Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the ma ...

  2. CF 1042 E. Vasya and Magic Matrix

    E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...

  3. 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 ...

  4. D. Vasya And The Matrix(Educational Codeforces Round 48)

    D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

  5. codeforces C. Vasya And The Mushrooms (思维+模拟)

    题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...

  6. [CF355C]Vasya and Robot(思维,贪心)

    题目链接:http://codeforces.com/contest/355/problem/C 题意:1~n n个物品各重wi,现在有一个人可以从左边拿和从右边拿, 左边拿一个物品的花费是l*wi, ...

  7. CF1016 D. Vasya And The Matrix

    传送门 [http://codeforces.com/group/1EzrFFyOc0/contest/1016/problem/D] 题意 已知矩阵n行m列,以及每一行,每一列所有元素的异或,用 a ...

  8. CodeForces - 1016D Vasya And The Matrix

    题面在这里! 很明显二进制每一位都是无关的,所以可以先把原问题简化:给矩阵中的每个位置填入0/1,使得特定行/列有奇数个1,其他行/列有偶数个1. 一个比较好想的方法是对行和列 列出 n+m 个异或方 ...

  9. PKU 3318 Matrix Multiplication(神奇的输入)

    #include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...

随机推荐

  1. Solaris/Linux 命令手册

    无意翻到之前收藏的一个文档,共享一下. Solaris/Linux 命令手册 1. 系统 # passwd:修改口令 # exit:退出系统 2. 文件 # cp:复制文件或目录,参数:-a递归目录, ...

  2. C笔试题(一)

    a和b两个整数,不用if, while, switch, for,>, <, >=, <=, ?:,求出两者的较大值. 答案: int func(int a, int b) { ...

  3. 请定义一个宏,比较两个数的a、b的大小,不能使用大于、小于、if语句

    请定义一个宏,比较两个数的a.b的大小,不能使用大于.小于.if语句 方法一:    #define max(a,b) ((((long)((a)-(b)))&0x80000000)?(b): ...

  4. layui 工具条实现分页

    1.页面 <div id="getShowTable" style="width: 100%; height: auto;clear: both;"> ...

  5. sql语句去重 最后部分没看 看1 有用

    一 数据库 1.常问数据库查询.修改(SQL查询包含筛选查询.聚合查询和链接查询和优化问题,手写SQL语句,例如四个球队比赛,用SQL显示所有比赛组合:举例2:选择重复项,然后去掉重复项:) 数据库里 ...

  6. VMware 虚拟机 Ubuntu 系统没有IP地址 解决:UP BROADCAST MULTICAST 问题

    VMware 虚拟机 ifconfig没有net_addr地址的解决方法 使用时间长的虚拟机,会莫名其妙的连接不上网 在终端中,使用ifconfig命令查看Ubuntu系统的IP地址,发现没有分配IP ...

  7. p1198&bzoj1012 最大数

    传送门(洛谷) 传送门(bzoj) 题目 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数 ...

  8. oracle环境变量

    1---此部分引自http://hi.baidu.com/jason_xux/item/1f44681d356927fa756a8480  感谢 ORA_NLS33 环境变量ora_nls33定义'l ...

  9. C# 绘制图表(柱状图,线性图,饼状图)

    http://blog.csdn.net/gisfarmer/article/details/3736452 Chart饼状图,每根柱子的宽度: int a = Chart1.Series[" ...

  10. Log4NET的日志框架的使用

    日志信息分类 1.等级由低到高:debug<info<warn<Error<Fatal; 2.区别: debug 级别最低,可以随意的使用于任何觉得有利于在调试时更详细的了解系 ...