• Nowcoder 练习赛26 D xor序列 ( 线性基 )


    题目链接

    题意 : 中文题、点链接

    分析 :

    对于给定的 X 和 Y 假设存在一个 Z

    使得 X (xor) Z = Y

    做一个变形

    X (xor) Z (xor) Y = 0

    X (xor) Y = Z

    也就是原集合中

    是否存在一个异或组合结果为 X (xor) Y

    线性基模板一套、AC

    #include<bits/stdc++.h>
    #define LL long long
    #define ULL unsigned long long
    
    #define scl(i) scanf("%lld", &i)
    #define scll(i, j) scanf("%lld %lld", &i, &j)
    #define sclll(i, j, k) scanf("%lld %lld %lld", &i, &j, &k)
    #define scllll(i, j, k, l) scanf("%lld %lld %lld %lld", &i, &j, &k, &l)
    
    #define scs(i) scanf("%s", i)
    #define sci(i) scanf("%d", &i)
    #define scd(i) scanf("%lf", &i)
    #define scIl(i) scanf("%I64d", &i)
    #define scii(i, j) scanf("%d %d", &i, &j)
    #define scdd(i, j) scanf("%lf %lf", &i, &j)
    #define scIll(i, j) scanf("%I64d %I64d", &i, &j)
    #define sciii(i, j, k) scanf("%d %d %d", &i, &j, &k)
    #define scddd(i, j, k) scanf("%lf %lf %lf", &i, &j, &k)
    #define scIlll(i, j, k) scanf("%I64d %I64d %I64d", &i, &j, &k)
    #define sciiii(i, j, k, l) scanf("%d %d %d %d", &i, &j, &k, &l)
    #define scdddd(i, j, k, l) scanf("%lf %lf %lf %lf", &i, &j, &k, &l)
    #define scIllll(i, j, k, l) scanf("%I64d %I64d %I64d %I64d", &i, &j, &k, &l)
    
    #define lson l, m, rt<<1
    #define rson m+1, r, rt<<1|1
    #define lowbit(i) (i & (-i))
    #define mem(i, j) memset(i, j, sizeof(i))
    
    #define fir first
    #define sec second
    #define VI vector<int>
    #define ins(i) insert(i)
    #define pb(i) push_back(i)
    #define pii pair<int, int>
    #define VL vector<long long>
    #define mk(i, j) make_pair(i, j)
    #define all(i) i.begin(), i.end()
    #define pll pair<long long, long long>
    
    #define _TIME 0
    #define _INPUT 0
    #define _OUTPUT 0
    clock_t START, END;
    void __stTIME();
    void __enTIME();
    void __IOPUT();
    using namespace std;
    struct L_B {
        LL d[65], p[65];
        int cnt;
    
        void init() {
            mem(d, 0);
            mem(p, 0);
            cnt = 0;
        }
    
        bool Insert(LL val) {
            for (int i = 32 ; i >= 0 ; i --) {
                if (val & (1LL << i)) {
                    if (!d[i]) {
                        d[i]=val;
                        break;
                    }
                    val^=d[i];
                }
            }
            return val > 0;
        }
    
        bool judge(LL val) {
            for (int i = 32 ; i >= 0 ; i --) {
                if (val & (1LL << i)) {
                    if (!d[i]) {
                        //d[i]=val;
                        break;
                    }
                    val^=d[i];
                }
            }
            return val > 0;
        }
    }LB;
    
    int main(void){__stTIME();__IOPUT();
    
        int n;
        sci(n);
    
        LB.init();
        for(int i=0; i<n; i++){
            LL tmp; scl(tmp);
            LB.Insert(tmp);
        }
    
        int Q;
        sci(Q);
        while(Q--){
            LL x, y;
            scll(x, y);
            if(!LB.judge(x^y)) puts("YES");
            else puts("NO");
        }
    
    
    __enTIME();return 0;}
    
    
    void __stTIME()
    {
        #if _TIME
            START = clock();
        #endif
    }
    
    void __enTIME()
    {
        #if _TIME
            END = clock();
            cerr<<"execute time = "<<(double)(END-START)/CLOCKS_PER_SEC<<endl;
        #endif
    }
    
    void __IOPUT()
    {
        #if _INPUT
            freopen("in.txt", "r", stdin);
        #endif
        #if _OUTPUT
            freopen("out.txt", "w", stdout);
        #endif
    }
    View Code
  • 相关阅读:
    数据--第28课
    数据--第27课
    数据--第26课
    数据--第25课
    数据--第23课
    数据--第24课
    数据--第22课
    数据--第21课-递归课后练习
    lambda表达式
    数组和链表
  • 原文地址:https://www.cnblogs.com/qwertiLH/p/9623207.html
Copyright © 2020-2023  润新知