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. iOS - UITableView 多选功能实现

    :自定义Cell中的代码 #import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property(nonatomic ...

  2. Java—将文件夹压缩为zip文件

    import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java ...

  3. DeadObjectException

    开发的过程中有时候会遇到DeadObjectException,说明系统service已经停止运行,解决的方式是在mainfistxml的application标签中添加android:hardwar ...

  4. JS高级——apply与call

    上下文调用模式 可以修改this的值,也就是可以修改函数的调用方式,apply.call可以修改函数调用上下文,也就是this的值 <script> var name = "莱昂 ...

  5. JS——client

    clientTop.clientLeft: clientTop:盒子的上boder clientLeft:盒子的左border clientWidth与clientHeight 1.在有DTD情况下: ...

  6. [Windows Server 2012] MySQL安全加固

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:MySQL ...

  7. java 向上,向下转型

    在对Java学习的过程中,对于转型这种操作比较迷茫,特总结出了此文.例子参考了<Java编程思想>. 目录 几个同义词 向上转型与向下转型 例一:向上转型,调用指定的父类方法 例二:向上转 ...

  8. C# 设定时间内自动关闭提示框

    通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net framework 没有为我们提供自动关闭MessageBox 的方法,要实现这个功能,我们需要使用Window API ...

  9. vue项目中使用百度地图的方法

    1.在百度地图申请密钥: http://lbsyun.baidu.com/  将 <script type="text/javascript" src="http: ...

  10. C++入职学习篇--新员工入职(持续更新)

    C++入职学习篇--新员工入职(持续更新) 本人菜鸟一枚,刚刚结束学业生涯,入职C++软件开发岗位,之前对C++一窍不通,刚刚入职,亚历山大,但为祖国和平发展,本人励志为中华崛起而奋斗,学不好C++誓 ...