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. netty学习:UDP服务器与Spring整合

    最近接到一个关于写UDP服务器的任务,然后去netty官网下载了netty的jar包(netty-4.0.49.Final.tar.bz2),解压后,可以看到上面有不少example,找到其中的关于U ...

  2. Python随笔-切片

    Python为取list部分元素提供了切片操作,list[begin:end]获取list的[begin,end)区间元素. 可以用负数索引. tuple.str都是list的一种,所以也适用. 可以 ...

  3. Laravel 5.4.36 session 发现

    由于Laravel session机制完全脱离了PHP自带的session机制  因此对于php.ini 配置session对Laravel  是不会产生影响 代码路径:   vendor/larav ...

  4. (转)50道JavaScript基础面试题(附答案)

    https://segmentfault.com/a/1190000015288700 1 介绍JavaScript的基本数据类型 Number.String .Boolean .Null.Undef ...

  5. 精美对UI设计界面赏析

    最美的UI设计界面赏析 . 喜欢就关注我吧

  6. cordova科大讯飞语音识别

    cordova-plugin-IFlyspeech 科大讯飞的语音听说读写的cordova插件 Supported Platforms iOS android Installation 插件安装命令: ...

  7. 控制台——屏蔽Ctrl+C快捷键对窗体的关闭功能

    导入SetCtrlHandlerHandler API //定义处理程序委托 public delegate bool ConsoleCtrlDelegate(int ctrlType); //导入S ...

  8. 开发者自建IM服务器必须要解决的几个问题!

    有很多朋友的项目需要用到即时通讯,几年前鄙人的项目也是如此,当年没有选择,只能自建了IM服务器,几年下来跨了不少的坑,想想都甚是后怕.总结此文为后来还想自建IM的朋友提个醒,或许能找到更好的解决之路. ...

  9. linux杀掉某个进程的脚本

    https://www.cnblogs.com/zeng1994/p/13a2c5a28e55dd3abc2c75a4fb80371a.html awk的说明: https://www.cnblogs ...

  10. ubuntu14.3安装phpmyadmin

    一.安装 sudo apt-get install phpmyadmin 二.软连接 cd /var/www/html/ sudo ln -s /usr/share/phpmyadmin phpmya ...