zoukankan      html  css  js  c++  java
  • cf 1016D

    D. Vasya And The Matrix
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    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.

    Output

    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.

    Examples
    input
    Copy
    2 3
    2 9
    5 3 13
    output
    Copy
    YES
    3 4 5
    6 7 8
    input
    Copy
    3 3
    1 7 6
    2 15 12
    output
    Copy
    NO




     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <string>
     7 #include <deque>
     8 using namespace std;
     9 #define ll long long 
    10 #define  N 109
    11 #define  gep(i,a,b)     for(int  i=a;i<=b;i++)
    12 #define  gepp(i,a,b)   for(int  i=a;i>=b;i--)
    13 #define  gep1(i,a,b)   for(ll i=a;i<=b;i++)
    14 #define  gepp1(i,a,b)  for(ll i=a;i>=b;i--)    
    15 #define  mem(a,b)  memset(a,b,sizeof(a))
    16 int n,m;
    17 int a[N],b[N],c[N][N];
    18 int main()
    19 {
    20     scanf("%d%d",&n,&m);
    21     int  x=0,y=0;
    22     gep(i,1,n) {
    23     scanf("%d",&a[i]);
    24     x^=a[i];
    25     } 
    26     gep(j,1,m){
    27         scanf("%d",&b[j]);
    28         y^=b[j];
    29     }
    30     if(x!=y){
    31         printf("NO
    ");
    32         return 0;
    33     }
    34     x^=a[1];x^=b[1];
    35     c[1][1]=x;
    36     gep(i,2,n){
    37         c[i][1]=a[i];
    38     }
    39     gep(j,2,m){
    40         c[1][j]=b[j];
    41     }
    42     printf("YES
    ");
    43     gep(i,1,n){
    44         gep(j,1,m){
    45             printf("%d%c",c[i][j],j==m?'
    ':' ');
    46         }
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    STM32的“外部中断”和“事件”区别和理解
    非线性函数的最小二乘拟合——兼论Jupyter notebook中使用公式 [原创]
    Jupyter 快捷键总结
    自制导纳信号发生器 [原创cnblogs.com/helesheng]
    Verilog HDL数组(存储器)操作
    一个有趣的异步时序逻辑电路设计实例 ——MFM调制模块设计笔记
    用NI的数据采集卡实现简单电子测试之6——数字I/O及测试平台
    用NI的数据采集卡实现简单电子测试之5——压控振荡器的测试
    用NI的数据采集卡实现简单电子测试之4——半导体温度传感器
    黑客用我们服务器挖矿了
  • 原文地址:https://www.cnblogs.com/tingtin/p/9487287.html
Copyright © 2011-2022 走看看