HDU5536:Chip Factory(字典树)
来源:互联网 发布:开门大吉是假唱知乎 编辑:程序博客网 时间:2024/06/07 22:55
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 2699 Accepted Submission(s): 1197
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
whichi,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?
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
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 integern , 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 most10 testcases with n>100
The first line of each test case is an integer
There are at most
Output
For each test case, please output an integer indicating the checksum number in a line.
Sample Input
231 2 33100 200 300
Sample Output
6400
Source
2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)
思路:范围只用1000,可以枚举i,j,每次删掉a[i],a[j]后跑一遍字典树更新最大值即可。
# include <iostream># include <cstdio># include <cstring># include <algorithm>using namespace std;const int maxn = 1e3+3;int arr[maxn], cnt;struct node{ int a[2], sum;}tri[maxn*100];void ins(int x){ int p = 0; for(int i=31; i>=0; --i) { int t = (x>>i)&1; if(!tri[p].a[t]) tri[p].a[t] = ++cnt; p = tri[p].a[t]; ++tri[p].sum; }}void del(int x){ int p = 0; for(int i=31; i>=0; --i) { int t = (x>>i)&1; p = tri[p].a[t]; --tri[p].sum; }}int query(int x){ int p = 0, ans = 0; for(int i=31; i>=0; --i) { int t = (x>>i)&1, rev = tri[p].a[!t], cur = tri[p].a[t]; if(rev && tri[rev].sum > 0) p = rev, ans |= (1<<i); else p = cur; } return ans;}int main(){ int t, n; scanf("%d",&t); while(t--) { cnt = 0; memset(tri, 0, sizeof(tri)); scanf("%d",&n); for(int i=0; i<n; ++i) scanf("%d",&arr[i]), ins(arr[i]); int ans = 0; for(int i=0; i<n; ++i) { del(arr[i]); for(int j=i+1; j<n; ++j) { del(arr[j]); ans = max(ans ,query(arr[i]+arr[j])); ins(arr[j]); } ins(arr[i]); } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- HDU5536 Chip Factory(01字典树)
- HDU5536:Chip Factory(字典树)
- HDU5536 Chip Factory(字典树)
- HDU5536 Chip Factory 【字典树】
- HDU5536 Chip Factory Trie(01字典树)
- hdu5536 Chip Factory (01字典树删除操作)
- HDU5536 chip factory 【01字典树】
- HDU5536 Chip Factory(trie树)
- hdu5536 Chip Factory(Tire)
- 【HDU5536 2015长春赛区 J】【字典树or暴力】Chip Factory 字典序做法+暴力做法
- HDU5536 Chip Factory(Trie树,二进制)
- hdu5536 Chip Factory (异或最大值)
- hdu5536 Chip Factory
- hdu5536 Chip Factory (暴力+优化)
- hdu 5563 Chip Factory(字典树)
- HDU 5536 Chip Factory (字典树)
- hdu 5536 Chip Factory(水 | 字典树)
- HDU 5536 Chip Factory(暴力 or 01字典树)
- hive-shell批量命令执行脚本
- STL中变动性算法
- 【2013年第四届蓝桥杯C/C++程序设计本科B组决赛 高僧斗法(编程大题) 】 + Nim 博弈
- JSTL标准标签库之核心标签(四)
- virtualBox端口转发
- HDU5536:Chip Factory(字典树)
- android中xml tools属性详解
- linux 安装python3.6
- C#中DateTime和秒之间的互转
- 自定义View(二)之Paint和Canvas详解
- 4.6内部类
- c++primer p101 3.4.2 练习3.24 未完成 很多问题
- Ubuntu 16.04下LNPM开发环境搭建(Linux + Nginx + PHP + MySQL)及一些概念总结
- 多系统端的上网利器 ShadowSocks,影梭