Chip Factory

Problem Description
John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large amounts of products, every processor has a serial number. More specifically, the factory produces n chips today, the i -th chip produced this day has a serial number si .

At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More specially, he writes a checksum number on the package, this checksum is defined as below:

maxi,j,k(si+sj)⊕sk

which i,j,k

are three different integers between 1

and n

. And ⊕

is symbol of bitwise XOR.

Can you help John calculate the checksum number of today?

 
Input
The first line of input contains an integer T

indicating the total number of test cases.

The first line of each test case is an integer n

, indicating the number of chips produced today. The next line has n

integers s1,s2,..,sn

, separated with single space, indicating serial number of each chip.

1≤T≤1000

3≤n≤1000

0≤si≤109

There are at most 10

testcases with n>100

 
Output
For each test case, please output an integer indicating the checksum number in a line.
 
Sample Input
2
3
1 2 3
3
100 200 300
 
Sample Output
6
400
 
题意:给你n个数,为你不同的三个下标i,j,k,其中两个之和异或第三个的最大值是多少
题解:我们枚举其中两个得和,去不同下标最大,显然就裸字典树了。
///meek

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const int N=;
#define mod 10000007 #define inf 10000007
#define maxn 10000 struct Trie{
int ch[N*][],siz,sum[N],word[N*];
void init(){mem(ch),siz=;mem(word);}
void insertt(int x) {
int u=,k=,W=x,each[];mem(each);
while(x) each[k++]=x%,x/=;
for(int i=;i>=;i--) {
int c=each[i];
if(!ch[u][c]) {
ch[u][c]=siz++;
word[ch[u][c]]++;
}
else {
word[ch[u][c]]++;
}
u=ch[u][c];
if(i==)sum[u]=W;
}
}
int ask(int x) {
int u=,each[],k=,WW=x,g;mem(each);
while(x) each[k++]=x%,x/=;
for(int i=;i>=;i--) {
int c=each[i];if(c==)g=;else g=;
if(ch[u][g]&&word[ch[u][g]]) {
u=ch[u][g];
}
else u=ch[u][c];
if(i==) return WW^sum[u];
}
}
void dele(int x) {
int u=,each[],k=,g;mem(each);
while(x) each[k++]=x%,x/=;
for(int i=;i>=;i--) {
int c=each[i];
u=ch[u][c];
word[u]--;
}
}
}trie; int main(){
int n,a[N],T=read();
while(T--) {
scanf("%d",&n);trie.init();
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
trie.insertt(a[i]);
}int ans=;
for(int i=;i<=n;i++) {
trie.dele(a[i]);
for(int j=i+;j<=n;j++) {
trie.dele(a[j]);
ans=max(ans,trie.ask(a[i]+a[j]));
trie.insertt(a[j]);
}
trie.insertt(a[i]);
}
printf("%d\n",ans);
}
return ;
}

代码

HDU 5536/ 2015长春区域 J.Chip Factory Trie的更多相关文章

  1. HDU 5534/ 2015长春区域H.Partial Tree DP

    Partial Tree Problem Description In mathematics, and more specifically in graph theory, a tree is an ...

  2. Travel(HDU 5441 2015长春区域赛 带权并查集)

    Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  3. HDU 5538/ 2015长春区域 L.House Building 水题

    题意:求给出图的表面积,不包括底面 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define ...

  4. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  5. ACM Changchun 2015 J. Chip Factory

    John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage larg ...

  6. HDU 5536 Chip Factory Trie

    题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...

  7. hdu 5446(2015长春网络赛J题 Lucas定理+中国剩余定理)

    题意:M=p1*p2*...pk:求C(n,m)%M,pi小于10^5,n,m,M都是小于10^18. pi为质数 M不一定是质数 所以只能用Lucas定理求k次 C(n,m)%Pi最后会得到一个同余 ...

  8. hdu 5443 (2015长春网赛G题 求区间最值)

    求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 2 ...

  9. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. 【java并发容器】并发容器之CopyOnWriteArrayList

    原文链接: http://ifeve.com/java-copy-on-write/ Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容 ...

  2. x264

    x264 x264  h264  1. x264调用主要过程 x264_param_default():设置参数集结构体x264_param_t的缺省值. x264_picture_alloc():为 ...

  3. JS——“==”与“===”

    ==: 两个等于号只是比较两个变量的值 var n1 = 1; var n2 = "1"; alert(n1 == n2);//返回true ===: 三个等于号不仅比较值而且比较 ...

  4. Mysql 之主从复制,mysql-proxy读写分离

    准备两台mysql服务器,master(192.168.43.64).slave(192.168.84.129) master配置: log-bin=mysql-bin binlog_format=m ...

  5. c# 图片资料

  6. php第十四节课

    投票 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  7. JavaScript day4(条件语句和条件运算符)

    1. 布尔值 布尔值要么是 true 要么是 false .它非常像电路开关, true 是“开”,false 是“关”.这两种状态是互斥的. 2. if 语句 if 语句用于在代码中做条件判断.关键 ...

  8. 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 1

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...

  9. 前端开发神器之chrome 综述

    作为前端工程师,也许你对chrome开发工具不陌生,但也谈不上对各个模块有深入了解. 本文主要是为chrome开发工具使用这个系列做个开篇. 参考资料: 谷歌开发者: https://develope ...

  10. 【codeforces 796A】Buying A House

    [题目链接]:http://codeforces.com/contest/796/problem/A [题意] 让你选一个最靠近女票的,且能买的房子; 输出你和你女票的距离; [题解] 枚举 [Num ...