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. scrapy爬取美女图片

    使用scrapy爬取整个网站的图片数据.并且使用 CrawlerProcess 启动. 1 # -*- coding: utf-8 -* 2 import scrapy 3 import reques ...

  2. SQL生成日期维度(到小时)

    #建表语句: CREATE TABLE [dbo].[Dim_日期3]( ) NOT NULL, [年] [int] NULL, ) NULL, ) NULL, ) NULL, ) NULL, ) N ...

  3. h5复制粘贴板,打开APP功能

    <div class="container"> <img src="../themes/mall/img/i_red_ad4.jpg"> ...

  4. ES5数组遍历

    reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值. array.reduce(function(total, currentValue, curren ...

  5. 【extjs6学习笔记】1.8 初始: ExtJS命名约定

    Convention for Description Example Class 类名应该在CamelCase中 MyCustomClass 类名应包含字母数字字符. 如果属于技术术语,则允许使用数字 ...

  6. cpp 计算程序运行时间的两种方法

    1. #include <time.h> time_t begin_t = clock(); // to do time_t finish_t = clock(); cout<< ...

  7. [nmon]使用nmon工具监控系统资源

    1.下载nmon 下载正确的nmon版本, 查看linux服务器版本,命令:lsb_release -a,查看到当前系统为RedHat 6.4 然后我们根据我们的linux版本,下载相应nmon版本, ...

  8. vijos 1320 清点人数

    背景 NK中学组织同学们去五云山寨参加社会实践活动,按惯例要乘坐火车去.由于NK中学的学生很多,在火车开之前必须清点好人数. 描述 初始时,火车上没有学生:当同学们开始上火车时,年级主任从第一节车厢出 ...

  9. python基础教程总结15——5 虚拟茶话会

    聊天服务器: 服务器能接受来自不同用户的多个连接: 允许用户同时(并行)操作: 能解释命令,例如,say或者logout: 容易拓展 套接字和端口: 套接字是一种使用标准UNIX文件描述符(file ...

  10. CoreData介绍

    http://blog.csdn.net/zh952016281/article/details/52105683 写在前面 在CoreData中有一些常用的类,称呼可能各不相同.所以这里先约定一些关 ...