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())==' ...
随机推荐
- GridView有用的小方法--2017年2月13日
原文:http://blog.csdn.net/21aspnet/article/category/285354更多:http://blog.csdn.net/21aspnet/article/cat ...
- nodejs调试:node-inspector
基于Chrome浏览器的调试器 既然我们可以通过V8的调试插件来调试,那是否也可以借用Chrome浏览器的JavaScript调试器来调试呢?node-inspector模块提供了这样一种可能.我们需 ...
- BZOJ2288:[POJ Challenge]生日礼物
浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?id ...
- app专项测试(稳定性测试、安全性测试)
https://blog.csdn.net/xiaomaoxiao336368/article/details/84887948
- javaScript之事件处理程序
事件就是用户或浏览器自身执行的某个动作,JavaScript与HTML的交互也是通过事件实现的.而相应某个事件的函数就叫做事件处理函数.包括以下几种: 1.HTML事件处理程序 某个元素支持的每 ...
- net.sf.json-lib maven依赖问题.
<dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</art ...
- 树莓派 Learning 002 装机后的必要操作 --- 04 添加软件源 之 添加公钥 --- 解决“由于没有公钥,无法验证下列签名”问题
树莓派 装机后的必要操作 - 添加软件源 解决 添加公钥 时会遇到的问题 当你添加完Debian的软件源后,在终端中执行sudo apt-get update时,会出现下面的错误:(这里我添加了3个软 ...
- R: 导入 csv 文件,导出到csv文件,;绘图后导出为图片、pdf等
################################################### 问题:导入 csv 文件 如何从csv文件中导入数据,?参数怎么设置?常用参数模板是啥? 解决方 ...
- sklearn常用数据的使用
from sklearn import datasets from sklearn.linear_model import LinearRegression #加载数据 loaded_data = d ...
- C#中的单体设计模式Singleton
经典的单体设计模式的实现就是 有一个Public的类,在这个类中,有一个私有的private的构造函数. 然后有一个静态方法,这个静态方法返回这个类的实例 举个例子如下 Public class My ...