hdu5536

来源:互联网 发布:淘宝100元左右的鼠标 编辑:程序博客网 时间:2024/06/06 08:45

这里写图片描述

#include <stdio.h>#include <algorithm>#include <string>#include <string.h>#include <math.h>#include <map>#include <stdlib.h>#include <iostream>using namespace std;typedef long long LL ;#define NULL -1const int N = 100008 ;int n ;struct Tire{       int root ;       int totel ;       int next[N][2] ;       int lable[N] ;       int cnt[N] ;       int Newnode(){           next[totel][0] = next[totel][1] = NULL ;           cnt[totel] = 0 ;           lable[totel] = 0 ;           return totel++ ;       }       void Clear(){            totel = 0 ;            root = Newnode() ;       }       void Add(int val){            int now = root ;            cnt[now]++ ;            for(int i = 31 ; i >= 0 ; i--){                int son = ( (1<<i) & val ) ? 1 : 0 ;                if(next[now][son] == NULL)                    next[now][son] = Newnode() ;                now = next[now][son] ;                cnt[now]++ ;            }            lable[now] = val ;       }       void Remove(int val){            int now = root ;            cnt[now]-- ;            for(int i = 31 ; i >= 0 ; i--){                int son = ( (1<<i) & val ) ? 1 : 0 ;                now = next[now][son] ;                cnt[now]-- ;            }       }       int  getmax(int val){            int now = root ;            for(int i = 31 ; i >= 0 ; i--){                 int son = ( (1<<i) & val ) ? 1 : 0 ;                 if(next[now][son^1] != NULL && cnt[next[now][son^1]] > 0)                     now = next[now][son^1] ;                 else now = next[now][son] ;            }            return val ^ lable[now] ;       }};const int maxn = 1008 ;int a[maxn] ;map<int , int> cnt ;map<int , int> ::iterator itLi ;int main(){    int t ;    scanf("%d" , &t) ;    while(t--){         scanf("%d" , &n) ;         cnt.clear() ;         for(int i = 1 ; i <= n ; i++){             scanf("%d" , &a[i]) ;             cnt[a[i]]++ ;         }         int ans = 0 ;         n = 0 ;         for(itLi = cnt.begin() ; itLi != cnt.end() ; itLi++){              int _c = min(3 , itLi->second) ;              int x = itLi->first ;              if(_c == 3){                  ans = max(ans , (x+x) ^ x) ;                  _c = 2 ;              }              while(_c--)  a[++n] = x ;         }         Tire tire ;         tire.Clear() ;         for(int i = 1 ; i <= n ; i++)  tire.Add(a[i]) ;         for(int i = 1 ; i <= n ; i++){              tire.Remove(a[i]) ;              for(int j = i+1 ; j <= n ; j++){                  tire.Remove(a[j]) ;                  ans = max(ans , tire.getmax(a[i]+a[j]) ) ;                  tire.Add(a[j]) ;              }              tire.Add(a[i]) ;         }         printf("%d\n" , ans) ;    }    return 0;}
0 0
原创粉丝点击