codeforces1016 D. Vasya And The Matrix(思维+神奇构造)
2 seconds
256 megabytes
standard input
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.
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.
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.
2 3
2 9
5 3 13
YES
3 4 5
6 7 8
3 3
1 7 6
2 15 12
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(思维+神奇构造)的更多相关文章
- 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 ...
- CF 1042 E. Vasya and Magic Matrix
E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点 ...
- 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 ...
- 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 ...
- codeforces C. Vasya And The Mushrooms (思维+模拟)
题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...
- [CF355C]Vasya and Robot(思维,贪心)
题目链接:http://codeforces.com/contest/355/problem/C 题意:1~n n个物品各重wi,现在有一个人可以从左边拿和从右边拿, 左边拿一个物品的花费是l*wi, ...
- CF1016 D. Vasya And The Matrix
传送门 [http://codeforces.com/group/1EzrFFyOc0/contest/1016/problem/D] 题意 已知矩阵n行m列,以及每一行,每一列所有元素的异或,用 a ...
- CodeForces - 1016D Vasya And The Matrix
题面在这里! 很明显二进制每一位都是无关的,所以可以先把原问题简化:给矩阵中的每个位置填入0/1,使得特定行/列有奇数个1,其他行/列有偶数个1. 一个比较好想的方法是对行和列 列出 n+m 个异或方 ...
- PKU 3318 Matrix Multiplication(神奇的输入)
#include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...
随机推荐
- android SDK manager 无法获取更新版本列表【转载】
http://mirrors.neusoft.edu.cn/eclipse/releases/luna/打开这个网址就可以看到adt的详细信息: http://developer.android.c ...
- JEECG datagrid 列表检索条件 添加下拉级联功能
$("#communityId").change( function(){ var id = $(this).children('option:selected').val(); ...
- 洛谷【P1090】合并果子&&洛谷【P1334】瑞瑞的木板
浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 合并果子题目传送门:https://www.luogu.org/problemnew/show/P1 ...
- Docker容器里的进程为什么要前台运行
<第一本Docker书>里面,讲到Docker容器启动web服务时,都指定了前台运行的参数,例如apache: ENTRYPOINT [ "/usr/sbin/apache2&q ...
- [FATAL_ERROR] Uncaught PDOException: There is already an active transaction
[FATAL_ERROR] Uncaught PDOException: There is already an active transaction ... $mysql->beginTran ...
- Java探索之旅(9)——数据和方法的可见性
注意,在UML图中,public-protected-private分别用+,-,#表示. 类中成员修饰符 在同一类访问 在同一包访问 在子类内访问 在不同包可访问 Public √ √ √ √ Pr ...
- HTTP 400 错误 编译器错误消息: CS0016
问题:运行程序时提示http 400错误 解决方法: 去掉勾 尝试将网页发布到本地IIS上,发现出现以下错误: 编译器错误消息: CS0016 解决编译器错误消息: CS0016:方法如下: 一般都是 ...
- MySql获取记录的名次
在oracle中有rownum之类的东西表示记录的名次,那么在MySql中怎么获取名次呢? as rank ) B 获取的rank就是名次了 user_id rank 134762 122139 ...
- 《精通Spring4.X企业应用开发实战》读后感第七章(AOP基础知识、jdk动态代理,CGLib动态代理)
- neon eclipse tomcat发布项目乱码
解决方法如图