HDU 5536 Chip Factory
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 620 Accepted Submission(s): 318
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
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?
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 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
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct Trie {
int ch[maxn][],cnt[maxn],tot;
int newnode() {
cnt[tot] = ch[tot][] = ch[tot][] = ;
return tot++;
}
void init() {
tot = ;
newnode();
}
void update(int v,int d,int rt = ) {
for(int i = ; i >= ; --i) {
int c = (v>>i)&;
if(!ch[rt][c]) ch[rt][c] = newnode();
rt = ch[rt][c];
cnt[rt] += d;
}
}
int match(int v,int rt = ,int ret = ) {
for(int i = ; i >= ; --i) {
int c = (v>>i)&;
if(ch[rt][c^] && cnt[ch[rt][c^]]) {
ret |= <<i;
rt = ch[rt][c^];
} else rt = ch[rt][c];
}
return ret;
}
}T;
int a[maxn];
int main() {
int kase,n,ret;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
T.init();
for(int i = ; i < n; ++i){
scanf("%d",a + i);
T.update(a[i],);
}
for(int i = ret = ; i < n; ++i){
T.update(a[i],-);
for(int j = i + ; j < n; ++j){
T.update(a[j],-);
ret = max(ret,T.match(a[i] + a[j]));
T.update(a[j],);
}
T.update(a[i],);
}
printf("%d\n",ret);
}
return ;
}
HDU 5536 Chip Factory的更多相关文章
- 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= ...
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- 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 字典树+bitset 铜牌题
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- ACM学习历程—HDU 5536 Chip Factory(xor && 字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题目大意是给了一个序列,求(si+sj)^sk的最大值. 首先n有1000,暴力理论上是不行的. ...
- HDU 5536 Chip Factory (暴力+01字典树)
<题目链接> 题目大意: 给定一个数字序列,让你从中找出三个不同的数,从而求出:$\max_{i,j,k} (s_i+s_j) \oplus s_k$的值. 解题分析:先建好01字典树,然 ...
- HDU 5536 Chip Factory Trie
题意: 给出\(n(3 \leq n \leq 1000)\)个数字,求\(max(s_i+s_j) \bigoplus s_k\),而且\(i,j,k\)互不相等. 分析: 把每个数字看成一个\(0 ...
随机推荐
- 单线程单元(STA)线程都应使用泵式等待基元
CLR 无法从 COM 上下文 0x20ad98 转换为 COM 上下文 0x20af08,这种状态已持续 60 秒.拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows ...
- WPF 控件树
WPF控件树按照基类进行分类,记录下来便于编写自定义控件时查阅 RangeBase范围控件 Thumb拖到控件 TextBoxBase文本控件 ItemControl组控件 ContrentContr ...
- 一本通 1434:【例题2】Best Cow Fences
Best Cow Fences 二分答案 + 前缀和 个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有). 本题的精度也是非常令人陶醉,请您自行体会吧! #includ ...
- 使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”
我买了一套正版的office 365装在我的windows10 上.但是每次打开excel都会报错,如图一.求教了微软技术人员,他们给出了以下办法: 图一 方法一: 修复安装Office ====== ...
- UVA 1220 Party at Hali-Bula (树形DP)
求一棵数的最大独立集结点个数并判断方案是否唯一. dp[i][j]表示以i为根的子树的最大独立集,j的取值为选和不选. 决策: 当选择i时,就不能选择它的子结点. 当不选i时,它的子结点可选可不选. ...
- fgetc, fgets, getc, getchar, gets, ungetc - 输入字符和字符串
总览 (SYNOPSIS) #include <stdio.h> int fgetc(FILE *stream); char *fgets(char *s, int size, FILE ...
- caffe的调试技巧 和 使用split层
1.网络中的layer层的输出,只要没有作为其他层的输入,caffe的日志就会把这个top输出(如果你用那个网站画网络结构图,你也会发现这种情况的层的颜色是不一样的,是紫色的) 2.如果你想看某一层在 ...
- SpringBoot整合Thymeleaf
一个整合Thymeleaf与Mybatis的CRUD例子 整合Mybatis例子 一.添加maven依赖 <dependency> <groupId>org.springfra ...
- javascript的offset、client、scroll使用方法
offsetTop 指元素距离上方或上层控件的位置,整型,单位像素. offsetLeft 指元素距离左方或上层控件的位置,整型,单位像素. offsetWidth 指元素控件自身的宽度,整型,单位像 ...
- Bootstrap历练实例:输入框组的大小
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...