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())==' ...
随机推荐
- NYOJ-括号配对问题--------待解决,RE
描述 现在,有一行括号序列,请你检查这行括号是否配对. 输入 第一行输入一个数N(0<N<=100),表示有N组测试数据.后面的N行输入多组输入数据,每组输入数据都是一个字符串S(S的 ...
- ACM学习历程—HDU5586 Sum(动态规划)(BestCoder Round #64 (div.2) 1002)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 题目大意就是把一段序列里面的数替换成f(x),然后让总和最大. 首先可以计算出初始的总和,以及每 ...
- Anthem.NET的 "Bad Response" 问题,及脚本调试技巧小结
今天解决了一位朋友使用 Anthem.NET 遇到的问题.他的代码在 Windows XP 的开发机器上反应正常,而部署到 2003 Server 的服务器上就提示 "BADRESPONSE ...
- ViewModel中C# Property自动添加OnPropertyChanged处理的小工具, 以及相应Python知识点
在做WPFMVVM中经常会遇到一些Model.ViewModel的属性添加添加私有字段和更改通知方法来支持Binding. 比如把: public class Test { public s ...
- Python:itertools库的使用
转于:https://blog.csdn.net/neweastsun/article/details/51965226 博主:neweastsun的专栏 介绍 itertools是python内置的 ...
- 杂项-Log:NLog
ylbtech-杂项-Log:NLog NLog是一个基于.NET平台编写的类库,我们可以使用NLog在应用程序中添加极为完善的跟踪调试代码. NLog是一个简单灵活的.NET日志记录类库.通过使用N ...
- Windows部署jenkins服务器
本次使用的操作系统: windows server 2012 r2vs版本: vs 2015jenkins: 2.19.4 一.下载jenkins http://mirror.xmission.com ...
- Levenberg-Marquardt优化算法以及基于LM的BP-ANN
一.LM最优化算法 最优化是寻找使得目标函数有最大或最小值的的参数向量.根据求导数的方法,可分为2大类.(1)若f具有解析函数形式,知道x后求导数速度快.(2)使用数值差分来求导数.根据使用模 ...
- Maven 命令格式及一些常用命令
Maven自身指定定义了一套对项目进行编译,测试,打包,运行,部署等工作的抽象.Maven自己是不实际负责这些工作的,而是把它们交给了插件.所以Maven命令的实际工作执行者是各种各样的插件. 要了解 ...
- 具体问题:3、hibernate跟Mybatis/ ibatis 的区别,为什么选择?
第一章 Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀 ...