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 ...
随机推荐
- 对javascript变量提升跟函数提升的理解
在写javascript代码的时候,经常会碰到一些奇怪的问题,例如: console.log(typeof hello); var hello = 123;//变量 function hello(){ ...
- Windows Server 2008 R2中上传和下载文件
在 Windows Server 2008 R2 中,使用服务器管理器来启用或禁用 Windows 功能,那在这个上面如何上传和下载文件呢? 1.在“服务器管理器”->“角色”->“web ...
- Openjudge 1.13-21:最大质因子序列
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- (三)SpringMVC之常用注解
SpringMVC的常用注解 注解 说明 @Controller 用于说明这个类是一个控制器 @RequestMapping 用于注释一个控制器类或者控制器类的方法 @RequestParam 用于将 ...
- java 核心技术卷一笔记 6 .2.3 接口 lambda 表达式 内部类
6.2.3 对象克隆 Cloneable 接口,这个接口指示一个类提供了一个安全的clone方法.(稍作了解) 为一个对象引用的变量建立副本时,原变量和副本都是同一个对象的引用,任何一个变量改变都 ...
- urlrrtrieve()实例_下载微博短视频
1.确定目标 在微博页面找一想要下载的短视频,通过审查元素找到视频的url. 如://f.us.sinaimg.cn/00150tBNlx07l0qjoSJi01040201m7z90k010.mp4 ...
- python中的循环语句-01
接触python已经一周时间,下面针对这一周python学习的情况做一梳理: 1)单行注释,使用一个#:多行注释,使用三个单引号(或者三个双引号)如: name = input("name: ...
- python基础一 day14 复习
迭代器和生成器迭代器:双下方法 : 很少直接调用的方法.一般情况下,是通过其他语法触发的可迭代的 —— 可迭代协议 含有__iter__的方法('__iter__' in dir(数据))可迭代的一定 ...
- 利用python进行数据分析3_Pandas的数据结构
Series #通过list构建Series ser_obj=pd.Series(range(10,20)) print(type(ser_obj))#<class 'pandas.core.s ...
- java运行环境jdk的安装和环境变量的配置教程
jdk的下载与安装 一.官网下载jdk 1.百度搜索jdk,进入官网,如下图所示: 官网下载jdk图1 2.在官网网站中找到合适的版本下载(以最新版本为例),如下图所示: 官网下载jdk图2 官网下载 ...