Educational Codeforces Round 48 (Rated for Div. 2)异或思维
题:https://codeforces.com/contest/1016/problem/D
题意:有一个 n * m 的矩阵, 现在给你 n 个数, 第 i 个数 a[ i ] 代表 i 这一行所有数的抑或和。
再给你 m 个数, 第 i 个数 b[ i ] 代表 i 这一列 所有数的抑或和。
问你是否能 构造出任意一个满足条件的矩阵, 不能输出 NO, 能输出YES 和那个 矩阵。
分析:考虑yes和no的情况,yes当且仅当,行的全部异或和等于列的全部异或和
原因:行的全部异或和x,就是整个数组所有数的异或和,列也同样分析 y,那么显而易见这俩个异或和x==y必须相同,矩阵才能被构造出来。
构造:简单的,就直接把一列数套在一行,另一列套在一列,是最简单的,但是考虑到第一行第一列的交叉位置,那么只要处理好这个交叉位置,那么就可以按照这种简单方法构造
考虑第一列,这一列除了第一个位置的异或和为x^a[i],那么要达到这一列异或和==b[i],那么这个位置只能是x^a[i]^b[i],由于x==y那么恰好对于考虑行的情况也是一样的道理
#include<bits/stdc++.h>
using namespace std;
const int M=;
int mp[M][M];
int a[M],b[M];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int x=,y=;
for(int i=;i<=n;i++){
cin>>a[i],x^=a[i];
}
for(int i=;i<=m;i++)
cin>>b[i],y^=b[i];
if(x!=y)
puts("NO");
else{ puts("YES");
x^=a[];
x^=b[];
mp[][]=x;
for(int i=;i<=n;i++)
mp[i][]=a[i];
for(int i=;i<=m;i++)
mp[][i]=b[i];
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
cout<<mp[i][j]<<" ";
cout<<endl;
}
}
return ;
}
Educational Codeforces Round 48 (Rated for Div. 2)异或思维的更多相关文章
- 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)
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 ...
- Educational Codeforces Round 48 (Rated for Div. 2)——A. Death Note ##
A. Death Note time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 48 (Rated for Div. 2)G. Appropriate Team
题意:求满足条件的(i,j)对数:\(gcd(v,a_i)=x,lcm(v,a_j)=y\) 题解:\(x|a_i,a_j|y\),\(x|y\),考虑质因子p,假设a_i中p次数为a,x中次数为b, ...
- 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 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
[链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...
- Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)
#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...
随机推荐
- chown virtualbox
virtualbox安装 root@cbill-VirtualBox:/# chown --help用法:chown [选项]... [所有者][:[组]] 文件... 或:chown [选项]... ...
- nginx log 切割
/logs/nginx/*/*access.log { daily rotate 30 missingok dateext #compress notifempty sharedscripts pos ...
- 第一个eclipse maven项目!我超全!
前言:以前一直用idea做东西,今天突然想试一下,没想到配置起来是真的麻烦!!!!会出现各种各样的问题,太晚了,本文只做出几处非常严重的问题,如有疑问,请私信,留言 准备:本文 JDK 1.8 ...
- mysql插入文本文档及读取
1.把本地的一个文件插入到数据库中,数据库字段用text保存 public static void main(String[] args) { PropKit.use(“pro.txt”);Druid ...
- kafka 零拷贝
kafka通过零拷贝实现高效的数据传输 https://blog.csdn.net/lxlmycsdnfree/article/details/78973864 Kafka零拷贝 https://bl ...
- PAT Advanced 1053 Path of Equal Weight (30) [树的遍历]
题目 Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight ...
- Vmotion迁移要求
- VCRedist_x86.exe Vcredist_x64.exe
Update for Visual C++ 2013 and Visual C++ Redistributable Package https://support.microsoft.com/en-u ...
- 打水滴(BFS)
在一个n行m列的网格中,某些位置存在一些水滴.嘟嘟进行q次打水滴操作,每次嘟嘟在某一个网格当中添加一个水滴,当某一网格中的水滴数量超过L时,该网格中的水滴变为四个水滴,并分别向上下左右四个方向飞出,每 ...
- LA 3882 经典约瑟夫环问题的数学递推解法
就是经典约瑟夫环问题的裸题 我一开始一直没理解这个递推是怎么来的,后来终于理解了 假设问题是从n个人编号分别为0...n-1,取第k个, 则第k个人编号为k-1的淘汰,剩下的编号为 0,1,2,3. ...