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 ...
随机推荐
- 如何写一个跨浏览器的事件处理程序 js
如何 写一个合格的事件处理程序,看如下代码: EventUtil可以直接拿去用 不谢 <!DOCTYPE html> <html> <head> <title ...
- Django中对单表的增删改查
之前的简单预习,重点在后面 方式一: # create方法的返回值book_obj就是插入book表中的python葵花宝典这本书籍纪录对象 book_obj=Book.objects.creat ...
- codeforces727C(交互)
题意 $n$个数,初始时不知道他们的值. 每次可以询问两个数的和,在$n$次询问内确定他们的值 $n \leqslant 5000$ Sol 首先询问出$1, 2$,$1, 3$,$2, 3$ 解个方 ...
- 安装ubuntu虚拟环境
一. 安装 1. 准备: 1). Oracle VM VirtualBox https://www.virtualbox.org/ 2). Ubuntu 18.04.2 LTS https://ubu ...
- Android 开机启动服务
在xml中注册 <!-- 开机广播 --> <receiver android:name=".receiver.BootBroadcastReceiver"> ...
- webview.loadUrl()可能会URLDecoder
与服务器交互时,客户端对userId进行了URLEncoder,然后在webview.loadUrl时将userId传给服务端,服务端再 URLDecoder userId 可是神奇的事情出现了,客户 ...
- POJ 2486 Apple Tree (树形DP,树形背包)
题意:给定一棵树图,一个人从点s出发,只能走K步,每个点都有一定数量的苹果,要求收集尽量多的苹果,输出最多苹果数. 思路: 既然是树,而且有限制k步,那么树形DP正好. 考虑1个点的情况:(1)可能在 ...
- MINST手写数字识别(三)—— 使用antirectifier替换ReLU激活函数
这是一个来自官网的示例:https://github.com/keras-team/keras/blob/master/examples/antirectifier.py 与之前的MINST手写数字识 ...
- win10 多桌面 win+tab | ctrl+win+左右箭头
win10 多桌面 win+tab | ctrl+win+左右箭头
- HTML之网页的基本介绍
一.web的基本介绍 web就是world wide web的缩写,称之为全球广域网,俗称WWW 可以将web理解成一种当前的互联网,对于我们来说更多的就是网站服务 网站我们可以理解成是由很多网页组合 ...