Educational Codeforces Round 48 D Vasya And The Matrix

EDU #48 D

 

题意:给定一个矩阵,已知每一行和每一列上数字的异或和,问矩阵上的数字是多少,不存在则输出NO。

 

思路:构造题,可以考虑只填最后一行,和最后一列,其中(n,m)要特判一下。其他格子给0即可。

   自己之前接触这类题目较少,感觉写这种题,自己的智商都提高了。

    

#include 
#include 
#include 
#include 
#include <string>
#include 
#include 
#include <set>
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue

typedef long long ll;
typedef unsigned long long ull;

typedef pair pll;
typedef pair<int ,int > pii;

//priority_queue q;//这是一个大根堆q
//priority_queue,greater >q;//这是一个小根堆q
#define fi first
#define se second
#define endl '\n'

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue, greater >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18

template
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------show time----------------*/
                const int maxn = 200;
                ll a[maxn],b[maxn];
                ll q[maxn],p[maxn];
                int n,m;
                ll ans[maxn][maxn];
int  main(){
                    OKC;
                    cin>>n>>m;
                    ll s1=0,s2 = 0;
                    for(int i=1; i<=n; i++)cin>>a[i], s1 ^=a[i];
                    for(int j=1; j<=m; j++)cin>>b[j], s2 ^=b[j];
                    if(s1!=s2){
                        puts("NO");
                        return 0;
                    }
                    ll ss  =s1;
                    cout<<"YES"<<endl;
                    for(int i=1; i<=n; i++)
                    {
                        for(int j=1; j<=m; j++)
                        {
                                if(i"0 ";
                                else {
                                    if(i==n&&j==m){
                                        cout<<(ss ^ a[n] ^ b[m]) <<" ";
                                    }
                                    else if(i==n){
                                        cout<" ";
                                    }
                                    else if(j==m){
                                        cout<" ";
                                    }
                                }
                        }

                        cout<<endl;
                    }


                    return 0;
}
EDU#48D

 

转载于:https://www.cnblogs.com/ckxkexing/p/9420155.html

你可能感兴趣的:(c/c++)