hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536
题面;
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 6277 Accepted Submission(s): 2847
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:
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,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
3
1 2 3
3
100 200 300
400
模板题
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e3+;
int tot;
int ch[*M][],vis[*M];
ll val[*M],a[M]; void init(){
memset(vis,,sizeof(vis));
tot = ;
ch[][] = ch[][] = ;
} void ins(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(!ch[u][v]){
ch[tot][] = ch[tot][] = ;
val[tot] = ;
vis[tot] = ;
ch[u][v] = tot++;
}
u = ch[u][v];
vis[u]++;
}
val[u] = x;
} void update(ll x,int c){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
u = ch[u][v];
vis[u] += c;
}
} ll query(ll x){
int u = ;
for(int i = ;i >= ;i --){
int v = (x>>i)&;
if(ch[u][v^]&&vis[ch[u][v^]]) u = ch[u][v^];
else u = ch[u][v];
}
return x^val[u];
} int main()
{
ios::sync_with_stdio();
cin.tie(); cout.tie();
int t,n,m;
cin>>t;
while(t--){
cin>>n;
ll mx = ;
init();
for(int i = ;i <= n;i ++)
cin>>a[i],ins(a[i]);
for(int i = ;i <= n;i ++){
for(int j = i+;j <= n;j ++){
update(a[i],-); update(a[j],-);
mx = max(mx,query(a[i]+a[j]));
update(a[i],); update(a[j],);
}
}
cout<<mx<<endl;
}
}
最新文章
- Finders Keepers
- Java开发之JSP行为
- [codevs1155][KOJ0558][COJ0178][NOIP2006]金明的预算方案
- TCP/IP协议学习笔记
- AutoMapper用法一瞥
- Android系列之UI组件----Menu菜单
- Android应用Design Support Library完全使用实例
- Java—Map.Entry
- php 建立类POST/GET 的HTTP请求
- IIs工作原理
- php 原生或curl获取 http headers
- YUM安装软件
- HighCharts中的无主题的2D折线图
- 使用easyui搭建网页架子
- JS两个页面通过URL传值
- mips编译器交叉编译openssl
- 学习C#(一)
- CSS的未来:一些试验性CSS属性
- Composite(组合)
- WinForm实现Rabbitmq官网6个案例-Hello World
热门文章
- #WEB安全基础 : HTML/CSS | 0x9美丽的饮料店
- 容器化系列 - GitLab启动和配置 on Docker
- MongoDB 创建索引的语法
- SQLServer之修改表值函数
- Linux PXE无人值守网络装机
- linux-arm 安装 dotnetcore
- GO语言学习笔记(一)
- spark-2.4.0-hadoop2.7-简单操作
- 使用PlanViz进行ABAP CDS性能分析
- pytorch Debug —交互式调试工具Pdb (ipdb是增强版的pdb)-1-在pytorch中使用