【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
【链接】 我是链接,点我呀:)
【题意】
告诉你每一行、每一列的异或和。
让你求出一个符合要求的原矩阵。
【题解】
显然应该有
a1^a2^....^an = b1^b2^....^bn
也即两边同时异或一下a1^b1
b1^a2^a3...^an =a1^b2^...^bn
我们设x=b1^a2^a3...^an =a1^b2^...^bn
然后我们就能得到一个符合要求的矩阵了

会发现第一列的异或和就是b1.第一行的异或和就是a1
因为x同时可以写成上面的那两种形式
第2到第n行以及第2到第m列显然也是满足要求的,下面全是0了
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N =1000000;
LL m,n,arr[N+10],brr[N+10],ans[1000][1000];
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n>> m;
int a=0,b=0;
for (int i = 0; i < n; i++)
{
cin >>arr[i];
if(i!=0) a=a^arr[i];
}
for (int i = 0; i < m; i++)
{
cin >>brr[i];
if(i!=0) b=b^brr[i];
}
a=a^brr[0];
b=b^arr[0];
if(a!=b){
cout << "NO" <<endl;
return 0;
}
rep1(i,0,n-1){
rep1(j,0,m-1){
if(i==0&&j==0) ans[i][j]=a;
else if(i==0)
{
ans[i][j]=brr[j];
}
else if(j==0)
{
ans[i][j]=arr[i];
}
}
}
cout << "YES" <<endl;
rep1(i,0,n-1){
rep1(j,0,m-1){
if(j!=0) cout << " ";
cout <<ans[i][j] ;
}
cout << endl;
}
return 0;
}
【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix的更多相关文章
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- 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 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,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 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
随机推荐
- Android学习笔记(17):文本框TextView类
TextView继承自View.用于显示文本.它有很多的子类,掌握其属性是非常重要的. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5 ...
- 我的红外arduino链接,!!!!
点击打开链接http://blog.csdn.net/g1342522389/article/details/46272473 一定要赞,小编非常辛苦.
- Tomcat启动时载入某个servlet
当我们做一个java项目时,有几个功能都须要载入servlet或者实现某个共同的方法,尽管我们一味地在每个功能中依次载入也不是不能够,可是当某个servlet 或者方法被频繁地载入和应用.我们将面向对 ...
- H3C子接口配置要点及实例说明
类型一:以太网子接口配置要点(单臂路由) 第一步:在路由器对端的交换机上配置好vlan信息(如vlan10/vlan20) 第二步:将交换机上与路由器直接相连的以太口配置成trunk口并同意 ...
- wpf datagridtemplatecolumn visibility binding
因为datagridtemplatecolumn不在Virsual Tree中,不能继承DataGrid的DataContext, 所以想要绑定到datagridtemplatecolumn的 vis ...
- oc6--类方法
// // main.m // 第一个OC类-类方法 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : N ...
- IJKPlayer问题集锦之不定时更新
1.IJKPlayer 不像系统播放器会给你旋转视频角度,所以你需要通过onInfo的what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED去获取 ...
- xocde8打印出:Presenting view controllers on detached view controllers is discouraged
原因: 是某个viewController的生命周期控制出现了错误,所以尽量避免一个controller的view去addsubview另一个controller的view,这样会破坏层级关系,导致第 ...
- 【撸码caffe 三】 caffe.cpp
caffe.cpp文件完成对网络模型以及模型配置参数的读入和提取,提供了网络模型训练的入口函数train和对模型的测试入口函数test.文件中使用了很多gflags和glog指令,gflags是goo ...
- [BZOJ 1579] Revamping Trails
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1579 [算法] dist[u][k]表示当前在点u,升级了k条道路,最短路径的长度 ...