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,暴力理论上是不行的. ...
随机推荐
- Dynamics 365中的应用程序介绍
本人微信和易信公众号:微软动态CRM专家罗勇 ,回复275或者20180630可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- SpringBoot实现全文搜索
• 全文搜索 • solr安装 • solr中文分词 • solr数据库导入 • solr数据查询 • solrj接口调用 1:
- npm缺少css-loader,/style-compiler,stylus-loader问题,npm没有权限无法全局更新问题【已解决】
ERROR in ./node_modules/css-loader!./node_modules/vue-loader/lib/style-compiler?{"vue":tru ...
- TDBGridEh 标头排序
数据源为adoQuery 1.首先设置dbGridEh里需要排序的字段的Title->Titlebutton属性为true 2.设置dgGridEh的optionsEh->dbhautoS ...
- c/c++ 重载运算符 标准库function的用法
重载运算符 标准库function的用法 问题:int(int, int)算不算一种比较通用的类型?? 比如函数: int add(int a, int b); 比如lambda:auto mod = ...
- UITableView编辑模式大全解
1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...
- 虚拟机配置Linux上网环境
概要:在虚拟机安装CentOS6.5的环境后,配置NAT模式,修改系统文件支持上网. (1)ip地址的配置,IP地址的子网掩码为255.255.255.0. (2)网关的指定,也就是默认路由,当我们需 ...
- 爬虫系列---scrapy post请求、框架组件和下载中间件+boss直聘爬取
一 Post 请求 在爬虫文件中重写父类的start_requests(self)方法 父类方法源码(Request): def start_requests(self): for url in se ...
- (十三)Batch Processing
In addition to being able to index, update, and delete individual documents, Elasticsearch also prov ...
- SQL Server中NULL的一个测试
我们都知道SQL Server中NULL是一个很特殊的存在,因为NULL不会等于任何值,且NULL也不会不等于任何值.对于NULL我们只能使用IS或IS NOT关键字来进行比较. 我们先来看看下面一个 ...