HDU 5536/ 2015长春区域 J.Chip Factory Trie
Chip Factory
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:
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?
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
,s
2
,..,s
n
, separated with single space, indicating serial number of each chip.
1≤T≤1000
3≤n≤1000
0≤si
≤10
9
There are at most 10
testcases with n>100
3
1 2 3
3
100 200 300
400
///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的更多相关文章
- HDU 5534/ 2015长春区域H.Partial Tree DP
Partial Tree Problem Description In mathematics, and more specifically in graph theory, a tree is an ...
- Travel(HDU 5441 2015长春区域赛 带权并查集)
Travel Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 5538/ 2015长春区域 L.House Building 水题
题意:求给出图的表面积,不包括底面 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define ...
- 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 ...
- 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 ...
- HDU 5536 Chip Factory Trie
题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...
- 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最后会得到一个同余 ...
- hdu 5443 (2015长春网赛G题 求区间最值)
求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 2 ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- 如何下载 Nginx (windows 版本)并且简单的使用
官网地址:http://nginx.org/ 进到官网 我这里下载的是 稳定版的 windows版本. 开始我们的简单测试 步骤一:找到nginx的压缩包,(随意找个地方)解压 步骤二:进入conf文 ...
- WinForm窗体项目 之 MySchool管理系统终极版
学习WinForm窗体程序也有一段时间了,今天就来尝试着来一个项目热热身~ 在我们通常使用的MySchool管理中,不外乎这几种功能:增.删.改.查.改密码 在过去的C#中确实是挺简单的,但是在学习了 ...
- [ USACO 2018 OPEN ] Out of Sorts (Platinum)
\(\\\) \(Description\) 对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: 数列\(A\)中\(A[1...i]\)的最大值不大于\(A[i+1-N]\)的最小值,我们 ...
- HTML TabIndex属性
TabIndex作用: tabindex:全局属性.指示其元素是否可以聚焦(获得焦点),以及它是否/在何处参与顺序键盘导航(因通常使用tab键操作,顾因此得名). 当使用tab键在网页控件中进行导航时 ...
- asp.net——统计输入的字符数目
asp.net——统计输入的字符数目 题目: 在页面中有一个TextBox输入框,一个显示文字用的Label,一个提交按钮Button.在TextBox中输入一段英文字母,点击按钮提交后统计其中字母‘ ...
- CSS——伪类
在a标签中运用最多: 1.a:link {color: #FF0000} /* 未访问的链接 */ 2.a:visited {color: #00FF00} /* 已访问的链接 */ 3.a:hove ...
- 学习笔记-java IO流总结 转载
1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作. Java所有的I/O机制都是基于数据流进行输入输出,这些数据流表示了字符或者字节数据的流动序列.Java的I/O流提供了读 ...
- React-Native WebView动态加载字体
背景 使用react-native构建的iOS/Android双端APP,通过WebView加载本地页面,需要根据服务器提供的字体列表实现下载和动态加载. 本地字体检查 有些字体手机操作系统已经提供了 ...
- 5.C#编写Redis访问类
那么通过前面几篇博文,服务端的安装和配置应该没什么问题了,接下来的问题是如何通过代码来访问Redis. 这里我们使用的库为: StackExchange.Redis GitHub:https://gi ...
- discuz 微社区开通
检测api: http://wsq.discuz.com/?a=apitest