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
- hdu5536
- HDU5536(字典树)
- hdu5536 Chip Factory
- hdu5536 Chip Factory (暴力+优化)
- HDU5536 Chip Factory(字典树)
- hdu5536 Chip Factory(Tire)
- HDU5536 Chip Factory(trie树)
- HDU5536 Chip Factory 【字典树】
- HDU5536 chip factory 【01字典树】
- HDU5536 Chip Factory(01字典树)
- HDU5536:Chip Factory(字典树)
- HDU5536-暴力|01字典树-J
- hdu5536 Chip Factory (异或最大值)
- HDU5536 Chip Factory(Trie树,二进制)
- hdu5536(字典树的插入和删除)
- HDU5536 Chip Factory Trie(01字典树)
- hdu5536 Chip Factory (01字典树删除操作)
- 【HDU5536 2015长春赛区 J】【字典树or暴力】Chip Factory 字典序做法+暴力做法
- ArrayDeque 源码
- android 非root实现静默安装
- 我遇到的kinect for windows2 USB不识别情况
- 单链表的反转
- 2015年大二上-数据结构-链表(4)-双链表算法库
- hdu5536
- Servlet学习笔记_03_使用servlet编写一个简单的helloworld程序
- 关于AFNetworking的一种错误!
- ubuntu 下如何使用svn
- arcgis锁
- 参数估计(续)
- 线程的优先级别
- 基本数据类型的转换和表示方法
- 上周二的一个面试(==)