zoukankan      html  css  js  c++  java
  • 【BZOJ-4269】再见Xor 高斯消元 + 线性基

    4269: 再见Xor

    Time Limit: 10 Sec  Memory Limit: 512 MB
    Submit: 131  Solved: 81
    [Submit][Status][Discuss]

    Description

    给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值。

    Input

    第一行一个正整数N。
    接下来一行N个非负整数。

    Output

    一行,包含两个数,最大值和次大值。

    Sample Input

    3
    3 5 6

    Sample Output

    6 5

    HINT

    100% : N <= 100000, 保证N个数不全是0,而且在int范围内

    Source

    Solution

    学线性基,还没完全学透,这是到纯模板题...于是...

    Code

    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    #define maxn 100010
    int a[maxn],n;
    void Gauss()
    {
        int tmp=0,i;
        for (int j=1<<30; j; j>>=1)
            {
                for (i=tmp+1; i<=n; i++)
                    if (a[i]&j) break;
                if (i>n) continue;
                swap(a[++tmp],a[i]);
                for (i=1; i<=n; i++)
                    if (i!=tmp && a[i]&j)
                        a[i]^=a[tmp];
            }
        n=tmp;
    }
    int main()
    {
        scanf("%d",&n);
        for (int i=1; i<=n; i++) scanf("%d",&a[i]);
        Gauss();
        int maxx=0;
        for (int i=1; i<=n; i++) maxx^=a[i];
        int cmaxx=maxx^a[n];
        printf("%d %d
    ",maxx,cmaxx);
        return 0;
    }
  • 相关阅读:
    数组、向量、矩阵的区别
    vue-cli3没有config.js文件的解决方法
    通用JS六
    通用JS五
    通用JS四
    通用JS三
    vue中sort排序与revers数据反序
    通用JS二
    VueX存储与本地存储以及会话存储的区别
    通用JS(一)
  • 原文地址:https://www.cnblogs.com/DaD3zZ-Beyonder/p/5516424.html
Copyright © 2011-2022 走看看