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 nn 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:

\display  maxi,j,k​(si​+sj​)⊕sk​

whichi,j,k are three different integers between 1 and n. And \oplus⊕ is symbol of bitwise XOR.

Can you help John calculate the checksum number of today?

Input Format

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 nn 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

Output Format

For each test case, please output an integer indicating the checksum number in a line.

样例输入复制

2
3
1 2 3
3
100 200 300

样例输出复制

6
400

题目来源

ACM Changchun 2015

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define ull unsigned long long
#define ll long long
#define N 30009
int num[N],tree[N][];
int t,n,a[];
int pos;
//01字典树
void insert(int x,int rt)
{
for(int i=;i>=;i--)
{
int y=;
if(x>>i&) y=;
if(!tree[rt][y]) tree[rt][y]=pos++;
rt=tree[rt][y];
num[rt]++;
}
}
void dele(int x,int rt)
{
for(int i=;i>=;i--)
{
int y=;
if(x>>i&) y=;
rt=tree[rt][y];
num[rt]--;//tree[rt][y] 还在,并不是真正的删除
}
}
int solve(int x,int rt)
{
int ret=;
/*
00001010
10100100是倒着来的
那么只要字典树里首位有1,就不可能找到10100100
*/
for(int i=;i>=;i--)//一定要倒过来,因为贪心,高位大,最终的结果才大
{
int y=;
if(x>>i&) y=;
if(tree[rt][y^]&&num[tree[rt][y^]])//num[tree[rt][y^1]]才有意义 {
rt=tree[rt][y^];
ret+=(<<i);//该位的异或为1
}
else{
rt=tree[rt][y];
}
}
return ret;
}
int main()
{
scanf("%d",&t);
while(t--)
{
for(int i=;i<N;i++)
{
num[i]=;
for(int j=;j<=;j++)
{
tree[i][j]=;
}
}
pos=;
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
insert(a[i],);
}
int ans=;
//每次要删除a[i],a[j] 因为i!=j!=k
//当然每次查询后,还要再次插入字典树
for(int i=;i<n;i++)
{ dele(a[i],);
for(int j=i+;j<n;j++)
{
dele(a[j],);
ans=max(ans,solve(a[i]+a[j],) );
insert(a[j],);
}
insert(a[i],);
}
printf("%d\n",ans);
}
return ;
}
 //9s  的暴力解法
#define N 1009
int t,n,a[N];
int ans;
int solve(int x,int y,int z)
{
return (x+y)^z;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int ans=;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
for(int k=j+;k<n;k++)
{
ans=max(ans,solve(a[i],a[j],a[k]) );
ans=max(ans,solve(a[i],a[k],a[j]) );
ans=max(ans,solve(a[k],a[j],a[i]) );
}
}
}
printf("%d\n",ans);
}
return ;
}

ACM Changchun 2015 J. Chip Factory的更多相关文章

  1. ACM Changchun 2015 L . House Building

    Have you ever played the video game Minecraft? This game has been one of the world's most popular ga ...

  2. ACM Changchun 2015 A. Too Rich

    You are a rich person, and you think your wallet is too heavy and full now. So you want to give me s ...

  3. HDU 5536/ 2015长春区域 J.Chip Factory Trie

    Chip Factory Problem Description John is a manager of a CPU chip factory, the factory produces lots ...

  4. hdu5536 Chip Factory 字典树+暴力 处理异或最大 令X=(a[i]+a[j])^a[k], i,j,k都不同。求最大的X。

    /** 题目:hdu5536 Chip Factory 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题意:给定n个数,令X=(a[i]+a[j] ...

  5. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  6. hdu5269 Chip Factory

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5536 题目: Chip Factory Time Limit: 18000/9000 MS ( ...

  7. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  8. hdu 5536 Chip Factory (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...

  9. Chip Factory(01字典树)

    Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others)  ...

随机推荐

  1. python实现批量远程执行命令及批量上传下载文件

    #!/usr/bin/env python # -*- coding: utf- -*- # @Time : // : # @Author : xuxuedong # @Site : # @File ...

  2. abp(net core)+easyui+efcore仓储系统——ABP总体介绍(一)

    在前面我已经介绍了ASP.NET MVC.ASP.NET Razor.WEBAPI等技术.我准备通过一个实践项目来整体应用一下之前介绍的技术.本系列是介绍基于ABP+EasyUI的Web开发框架的形成 ...

  3. android应用开发全程实录-你有多熟悉listview?

    今天给大家带来<android应用开发全程实录>中关于listview和adatper中的部分.包括listview的基本使用,listview的优化等. 我们经常会在应用程序中使用列表的 ...

  4. Spring的七种事务传播机制

    概述 当我们调用一个基于Spring的Service接口方法(如UserService#addUser())时,它将运行于Spring管理的事务环境中,Service接口方法可能会在内部调用其它的Se ...

  5. swift 基础-1

    一.常量与变量 var testVariable = 42         testVariable = 50         println(testVariable)                ...

  6. When you want to give up, remember why you started.

    When you want to give up, remember why you started.当你想要放弃的时候,请记住当初你为何而开始.

  7. 关于Kendo UI 开发教程

    Kendo UI 开发教程 jQuery UI 是一套 JavaScript 函式库,提供抽象化.可自订主题的 GUI 控制项与动画效果.基于 jQuery JavaScript 函式库,可用来建构互 ...

  8. LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例

    题目描述 一共有 nnn个数,第 iii 个数 xix_ix​i​​ 可以取 [ai,bi][a_i , b_i][a​i​​,b​i​​] 中任意值.设 S=∑xi2S = \sum{{x_i}^2 ...

  9. Set、Map及数组去重

    https://cloud.tencent.com/developer/article/1437254 https://blog.csdn.net/weixin_34247299/article/de ...

  10. python_88_xml模块

    xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单例如创建xmltest.xml文件内容如上 注:/代表自结束符号 <?xml version=&quo ...