当前位置:网站首页>Codeforces 1629 E. grid XOR - simple thinking

Codeforces 1629 E. grid XOR - simple thinking

2022-06-12 13:32:00 Tianyi City*

This way

The question :

Give you a two-dimensional array b,b[i][j]=a[i][j+1]^a[i][j-1]^a[i+1][j]^a[i-1][j]. Let you output a The exclusive or sum of all values of .

Answer key :

I didn't see the XOR and , So it's early enough , Maybe it wants to find rules from this ? I'll find out later

First, let me assume that the first line is all 0, How to think of all for 0 Well , Because we need a starting point … I'll just give you more details .
The first line is all 0 after , Is the second line all known , Then the third line , In the fourth row … All can be pushed out . At first I thought I would make mistakes in the last line , So it's just a bit of a painting , But it doesn't seem to go wrong ? Probably originally a[1][1] Should be x Of , I become 0 after x I was a[1][2] and a[2][1] Let's go .
That's too much water , Just calculate directly .

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
int a[N][N],b[N][N],n;
int main()
{
    
    int t;
    scanf("%d",&t);
    while(t--){
    

        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                scanf("%d",&b[i][j]);
        for(int i=1;i<n;i++)
            for(int j=1;j<=n;j++)
                    a[i+1][j]=b[i][j]^a[i][j-1]^a[i][j+1]^a[i-1][j];
        int ans=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                ans^=a[i][j],a[i][j]=0;
        printf("%d\n",ans);
    }
    return 0;
}

原网站

版权声明
本文为[Tianyi City*]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010516109716.html