【链接】 我是链接,点我呀:)

【题意】

告诉你每一行、每一列的异或和。
让你求出一个符合要求的原矩阵。

【题解】

显然应该有
a1^a2^....^an = b1^b2^....^bn
也即两边同时异或一下a1^b1
b1^a2^a3...^an =a1^b2^...^bn
我们设x=b1^a2^a3...^an =a1^b2^...^bn
然后我们就能得到一个符合要求的矩阵了
![](https://images2018.cnblogs.com/blog/1251265/201808/1251265-20180804114209048-744453766.png)
会发现第一列的异或和就是b1.第一行的异或和就是a1
因为x同时可以写成上面的那两种形式
第2到第n行以及第2到第m列显然也是满足要求的,下面全是0了

【代码】

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  4. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  5. #define all(x) x.begin(),x.end()
  6. #define pb push_back
  7. #define lson l,mid,rt<<1
  8. #define rei(x) scanf("%d",&x)
  9. #define rel(x) scanf("%lld",&x)
  10. #define res(x) scanf("%s",x)
  11. #define rson mid+1,r,rt<<1|1
  12. using namespace std;
  13. const double pi = acos(-1);
  14. const int dx[4] = {0,0,1,-1};
  15. const int dy[4] = {1,-1,0,0};
  16. const int N =1000000;
  17. LL m,n,arr[N+10],brr[N+10],ans[1000][1000];
  18. int main()
  19. {
  20. #ifdef LOCAL_DEFINE
  21. freopen("rush_in.txt", "r", stdin);
  22. #endif
  23. ios::sync_with_stdio(0),cin.tie(0);
  24. cin >> n>> m;
  25. int a=0,b=0;
  26. for (int i = 0; i < n; i++)
  27. {
  28. cin >>arr[i];
  29. if(i!=0) a=a^arr[i];
  30. }
  31. for (int i = 0; i < m; i++)
  32. {
  33. cin >>brr[i];
  34. if(i!=0) b=b^brr[i];
  35. }
  36. a=a^brr[0];
  37. b=b^arr[0];
  38. if(a!=b){
  39. cout << "NO" <<endl;
  40. return 0;
  41. }
  42. rep1(i,0,n-1){
  43. rep1(j,0,m-1){
  44. if(i==0&&j==0) ans[i][j]=a;
  45. else if(i==0)
  46. {
  47. ans[i][j]=brr[j];
  48. }
  49. else if(j==0)
  50. {
  51. ans[i][j]=arr[i];
  52. }
  53. }
  54. }
  55. cout << "YES" <<endl;
  56. rep1(i,0,n-1){
  57. rep1(j,0,m-1){
  58. if(j!=0) cout << " ";
  59. cout <<ans[i][j] ;
  60. }
  61. cout << endl;
  62. }
  63. return 0;
  64. }

【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix的更多相关文章

  1. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

  2. 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot

    [链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...

  3. 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 ...

  4. 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement

    [链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...

  5. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

  6. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  7. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  8. 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 ...

  9. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

随机推荐

  1. Android学习笔记(17):文本框TextView类

    TextView继承自View.用于显示文本.它有很多的子类,掌握其属性是非常重要的. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5 ...

  2. 我的红外arduino链接,!!!!

    点击打开链接http://blog.csdn.net/g1342522389/article/details/46272473 一定要赞,小编非常辛苦.

  3. Tomcat启动时载入某个servlet

    当我们做一个java项目时,有几个功能都须要载入servlet或者实现某个共同的方法,尽管我们一味地在每个功能中依次载入也不是不能够,可是当某个servlet 或者方法被频繁地载入和应用.我们将面向对 ...

  4. H3C子接口配置要点及实例说明

     类型一:以太网子接口配置要点(单臂路由)  第一步:在路由器对端的交换机上配置好vlan信息(如vlan10/vlan20)  第二步:将交换机上与路由器直接相连的以太口配置成trunk口并同意 ...

  5. wpf datagridtemplatecolumn visibility binding

    因为datagridtemplatecolumn不在Virsual Tree中,不能继承DataGrid的DataContext, 所以想要绑定到datagridtemplatecolumn的 vis ...

  6. oc6--类方法

    // // main.m // 第一个OC类-类方法 #import <Foundation/Foundation.h> // 1.编写类的声明 @interface Iphone : N ...

  7. IJKPlayer问题集锦之不定时更新

    1.IJKPlayer 不像系统播放器会给你旋转视频角度,所以你需要通过onInfo的what == IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED去获取 ...

  8. xocde8打印出:Presenting view controllers on detached view controllers is discouraged

    原因: 是某个viewController的生命周期控制出现了错误,所以尽量避免一个controller的view去addsubview另一个controller的view,这样会破坏层级关系,导致第 ...

  9. 【撸码caffe 三】 caffe.cpp

    caffe.cpp文件完成对网络模型以及模型配置参数的读入和提取,提供了网络模型训练的入口函数train和对模型的测试入口函数test.文件中使用了很多gflags和glog指令,gflags是goo ...

  10. [BZOJ 1579] Revamping Trails

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1579 [算法] dist[u][k]表示当前在点u,升级了k条道路,最短路径的长度 ...