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;
    }
  • 相关阅读:
    mysql 权限问题
    触发器作用
    带有循环功能的存储过程
    带有条件判断的存储过程
    数据存储 三大范式-----------待续
    存储过程自 带条件判断的存储过程
    线程异步更新UI
    TextBox只能输入数字
    C#中无边框窗体移动或拖控件移动窗体
    classloader原理
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7223559.html
Copyright © 2011-2022 走看看