zoukankan      html  css  js  c++  java
  • LibreOJ #113. 最大异或和

    二次联通门 : LibreOJ #113. 最大异或和

    /*
        LibreOJ #113. 最大异或和
        
        线性基
         
        插入 与 查询最大值
        
        说一下我在学习线性基时遇到的一些问题
        
        1.线性基指的是一个数集
        2.。。。没了。
        
        一开始反复看了好几遍,不知道线性基是个什么东西
        后来突然明白是个数集而不是个操作什么的。。 
        
        突然不能用printf了。。。用printf输出就是负数。。
        只能用cout了。。 
    */
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    
    inline void read (long long &now)
    {
        register char word = getchar ();
        bool temp = false;
        for (now = 0; word < '0' || word > '9'; word = getchar ())
            if (word == '-')
                temp = true;
        for (; word >= '0' && word <= '9'; now = now * 10 + word - '0', word = getchar ());
        if (temp)
            now = -now;
    }
    
    
    class Linear_Base_Type
    {
        
        static const int _L = 62;
        
        private :
            
            long long number[_L | 1];
            
        public :
            
            inline bool Insert (register long long key)
            {
                for (register int i = _L; i >= 0; i --)
                    if (key & (1LL << i))
                    {
                        if (!number[i])
                        {
                            number[i] = key;
                            break;
                        }
                        key ^= number[i];
                    }
                return key > 0;
            }
            
            long long Query_Maxn ()
            {
                long long res = 0;
                
                for (register int i = _L; i >= 0; i --)
                    res = ((res ^ number[i]) > res) ? (res ^ number[i]) : res;
                    
                return res;
            }
    };
    
    Linear_Base_Type Make;
    
    int main (int argc, char *argv[])
    {
        long long N;
        read (N);
        long long x;
        
        for (register int i = 1; i <= N; i ++)
        {
            read (x);
            
            Make.Insert (x); 
        }
        std :: ios :: sync_with_stdio (false);
        std :: cout << Make.Query_Maxn ();
        
        return 0;
    }
  • 相关阅读:
    Leetcode 1489找到最小生成树李关键边和伪关键边
    Leetcode 113 路径总和 II
    hdu 1223 还是畅通工程
    hdu 1087 Super Jumping! Jumping! Jumping!
    hdu 1008 Elevator
    hdu 1037 Keep on Truckin'
    湖工oj 1241 畅通工程
    湖工oj 1162 大武汉局域网
    hdu 2057 A + B Again
    poj 2236 Wireless Network
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7223559.html
Copyright © 2011-2022 走看看