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
,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
模板题
#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;
}
}
hdu 5536 Chip Factory (01 Trie)的更多相关文章
- HDU 5536 Chip Factory 【01字典树删除】
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5536 Chip Factory Time Limit: 18000/9000 MS (Java/Ot ...
- HDU 5536 Chip Factory 字典树+贪心
给你n个数,a1....an,求(ai+aj)^ak最大的值,i不等于j不等于k 思路:先建字典树,暴力i,j每次删除他们,然后贪心找k,再恢复i,j,每次和答案取较大的,就是答案,有关异或的貌似很多 ...
- HDU 5536 Chip Factory 字典树
Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- hdu 5536 Chip Factory 字典树+bitset 铜牌题
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5536 Chip Factory Trie
题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
随机推荐
- NET Core应用中使用缓存
NET Core应用中使用缓存 .NET Core针对缓存提供了很好的支持 ,我们不仅可以选择将数据缓存在应用进程自身的内存中,还可以采用分布式的形式将缓存数据存储在一个“中心数据库”中.对于分布式缓 ...
- pip 使用豆瓣源
pip 使用豆瓣源 由于pip 默认使用Python的官方源pypi.python.org/pypi,导致我们经常使用pip装包时速度过慢或者无法安装(请求超时)等问题, 所以国内用户建议使用pip ...
- Git:六、分支管理(指针操作)
1.基本操作 1)创建分支 git branch <name> 2)切换分支 git checkout <name> 1)&2)创建并切换分支 git checkout ...
- ext遍历表单中所有输入项,并全部设置为只读
baseInfoForm.getForm().getFields().each(function (field) { // 设置只读 field.setReadOnly(true); })
- nginx + flask + uwsgi + centos + python3 搭建web项目
1. python3之前已经搭建好,安装flask,使用 pip3 intall flask,这个比较简单,就不过多介绍 2.我在 /usr/local/nginx/html3 (html3是我新建 ...
- SQL Server 迁移至MySQL 关键步骤的梳理总结
迁移主要是通过Navicat工具来实现的.迁移工具的选定在此不讨论. 迁移前准备 1.提前通知DBA\SA\BI等,并确认发布计划及数据库迁移方案. 2.梳理出SQL Server DB 中影响业务 ...
- 7 Best Free RAR Password Unlocker Software For Windows
Here is the list of Best Free RAR Password Unlocker Software for Windows. These software run differe ...
- C#基础知识之Dictionary
最近使用了Dictionary,出现了意想不到的错误,先记录一下自己遇到的问题以及目前我的解决方法,然后温习一下Dictionary的基础用法. 一.自己遇到的问题 1.代码如下: namespace ...
- 研究好vif 和vshow
另外从源头上处理的???,怎么自己排查出错误??必须 ??https://www.jb51.net/article/124116.htm
- kafka-rest:怎么愉快的build?
愉快的build该项目吧 git clone https://github.com/confluentinc/kafka-restmvn clean install -Dmaven.test.skip ...