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. PHP流程控制语句(if,foreach,break......)

    背景:PHP程序中,必不可少的要用到流程控制语句.这次对于流程控制语句进行一些总结. 条件控制语句和循环控制语句是两种基本的语法结构,它们都是用来控制程序执行流程.也是构成程序的主要语法基础. 一.程 ...

  2. PHP中单例模式与工厂模式

    单例模式概念 单例模式是指整个应用中类只有一个对象实例的设计模式. 单例模式的特点 一个类在整个应用中只有一个实例 类必须自行创建这个实例 必须自行向整个系统提供这个实例 php中使用单例模式的原因 ...

  3. c++ 以二进制和以文本方式读写文件的区别

    在c++项目开发中,时常涉及到文件读写操作.因此在这里先简单梳理和回顾一下文本模式和二进制模式在进行文件读写上的区别. 1.linux平台下文本文件和二进制文件的读写 在linux平台下进行文件读写时 ...

  4. Tcl之looping

    1 While loop while test body The while command evaluates test as an expression. If test is true, the ...

  5. 5.C#编写Redis访问类

    那么通过前面几篇博文,服务端的安装和配置应该没什么问题了,接下来的问题是如何通过代码来访问Redis. 这里我们使用的库为: StackExchange.Redis GitHub:https://gi ...

  6. LVS部分调度算法的适应场景分析

    1.轮叫调度算法(RR)假设所有服务器处理性能均相同,不管服务器的当前连接数和响应速度.该算法相对简单,不适用于服务器组中处理性能不一的情况,而且当请求服务时间变化比较大时,轮叫调度算法容易导致服务器 ...

  7. C# textbox 获得焦点

    this.ActiveControl = txt_core;

  8. C# 控件调整

    //最大化 this.WindowState = FormWindowState.Maximized; //去掉标题栏 this.FormBorderStyle = FormBorderStyle.N ...

  9. excel 类获取起始列和使用列

    m_excel.OpenWorkBook(sFileName, sSheetDrawingList); // Get drawing info int iStartRow = 0, iStartCol ...

  10. Linux常用命令(简单的常用)

      1. 文件和目录 cd /home 进入 '/ home' 目录' cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd 进入个人的主目录 cd ~user1 进入个人的主目录 cd ...