首页 > 其他分享 >Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix

Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix

时间:2023-04-24 23:03:30浏览次数:30  
标签:Vasya Educational Rated xor matrix int long include define

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
inputCopy
2 3
2 9
5 3 13
outputCopy
YES
3 4 5
6 7 8
inputCopy
3 3
1 7 6
2 15 12
outputCopy
NO
题意:给你一个矩阵每行,每列的异或和,如果可以构造出原矩阵,输出一种情况;否则输出NO

思路:判断 yes or no 很容易,至于构造,感觉只要做过类似的就应该会做了——-构造 n-1 * m-1 的矩阵,这里面值随便填,然后在最后一行,一列按题目要求求出即可。(套路题。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<sstream>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 20005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-6
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

int rr[maxn], cc[maxn];
int a[500][500];


int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int i, j;
    int sum1 = 0, sum2 = 0;
    for (i = 0; i < n; i++) {
        cin >> rr[i];
        if (i == 0)sum1 = rr[i];
        else sum1 ^= rr[i];
    }
    for (i = 0; i < m; i++) {
        cin >> cc[i];
        if (i == 0)sum2 = cc[i];
        else sum2 ^= cc[i];
    }
    if (sum1 != sum2) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
        for (i = 0; i < n - 1; i++) {
            for (j = 0; j < m - 1; j++) {
                a[i][j] = 0;
            }
        }
        for (i = 0; i < n; i++) {
            int k = a[i][0];
            for (j = 1; j < m - 1; j++) {
                k ^= a[i][j];
            }
            a[i][m - 1] = k ^ rr[i];
        }
        for (i = 0; i < m ; i++) {
            int k = a[0][i];
            for (j = 1; j < n - 1; j++)
                k ^= a[j][i];
            a[n - 1][i] = k ^ cc[i];
        }
        for (i = 0; i < n; i++) {
            for (j = 0; j < m; j++) {
                cout << a[i][j] << ' ';
            }
            cout << endl;
        }
    }
}

标签:Vasya,Educational,Rated,xor,matrix,int,long,include,define
From: https://blog.51cto.com/u_15657999/6222001

相关文章

  • Educational Codeforces Round 47 (Rated for Div. 2) C. Annoying Present 数
    Alicegotanarrayoflengthnasabirthdaypresentonceagain!Thisisthethirdyearinarow!Andwhatismoredisappointing,itisoverwhelmenglyboring,filledentirelywithzeros.BobdecidedtoapplysomechangestothearraytocheerupAlice.......
  • Educational Codeforces Round 147
    A题意思路有前导零结果直接为0,出现在第一位的?贡献为9,其他地方的?贡献为10。代码#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;chars[10];intmain(){intT;scanf("%d",&T);while(T--){scanf("%s",s);......
  • Educational Codeforces Round 147 (Rated for Div. 2)
    题目链接B核心思路真的需要加强了,看到这个最大值和最小值我们其实也需要往对应的最大值和最小值的相关操作去想,不如前缀最小值/前缀最大值或者是后缀最小值/后缀最大值。这里一个比较直接的想法就是想找到不同的地方,然后看不可以扩展。那么怎么看是否可以扩展呢,如果是左边的话......
  • Educational Codeforces Round 127 (Rated for Div. 2)
    题目链接D核心思路首先挖掘下操作的性质吧:x>1&&x+3<10:1xx+1x+2x+310我们可以发现这样子好像对于我们的结果是没有影响的,答案还是9.所以这个性质就挖掘出来了啊,只要我们把一段连续的插入到对应的区间里面就好了。也就是只要这个区间的左端点小于插入连续的数的最小值,......
  • Educational Codeforces Round 147 (A-D)
    A.Matching橘子熊:这题太简单了我不想写题面Description给定给一个带问号的字符串,求有多少种可能的数字Input多次询问,一次一个字符串Output对于每次询问,输出可能的数字的总数数据范围与约定2e5次询问,单词询问不超过5个字符思路主要思路签到题大部分情况下,一个......
  • Educational Codeforces Round 39 (Rated for Div. 2) -- D. Timetable (DP)
    写得很折磨人,每次dp都写个一个多小时,写出来明明觉得不难.题目大意:可以进行K次操作,把删除1,进行k次操作后每行第一个1和最后一个1的位置相减的绝对值加1得到的结果最小。做法:每次肯定是要从左删或者从右边删,然后顺着这个思路,先把每行的进行小于等于k次操作时,每行最小......
  • Educational Codeforces Round 147 (Rated for Div. 2)
    EducationalCodeforcesRound147(RatedforDiv.2)链接EducationalCodeforcesRound147(RatedforDiv.2)A题如果第一位数是0,直接打印0如果第一位数是'?',有9个数可以选择,如果其他位数是'?',有10中情况选择,相乘就可以了#include<iostream>#include<algo......
  • Educational Codeforces Round 113 (Rated for Div. 2)
    题目链接B核心思路这个题目我觉得很好。首先分析下吧,如果有人需要执行操作二那么我们肯定就是给他们都打上平局是最优的。那么如果有人需要执行操作一呢,那么我们就可以把这些需要执行操作1的都搞一起。然后是他们成一个环。这样肯定就保证了每个人都会赢上一次。C核心思路......
  • [Educational Codeforces Round 118 (Rated for Div. 2)]题解
    A题意:给定两个数,每一个数有两个属性,第一个属性是p1,第二个属性是p2.表示这个数有p2个后缀0.这个数本身等于p1后面加p2个0.问给你两个这种数,判断大小。思路:赛场上想到的:如果最终的长度不一样,可以直接根据长度判断。如果相等,就把后缀0加上直接比较大小就可以(比较字典序的大小),但......
  • Educational Codeforces Round 110 (Rated for Div. 2) C. Unstable String(状态机)
    https://codeforces.com/contest/1535/problem/C题目大意:给定一个字符串s,由10?组成:?每次都可以任意替换成0或者1问我们这个子字符串中,能够组成010101这样两两互不相等的字符串的数量最大是多少?input30?10????10??1100output8625#include<bits/stdc++.h>usin......