ACM Changchun 2015 J. Chip Factory
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
题目来源
#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的更多相关文章
- 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 ...
- 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 ...
- HDU 5536/ 2015长春区域 J.Chip Factory Trie
Chip Factory Problem Description John is a manager of a CPU chip factory, the factory produces lots ...
- 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] ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- hdu5269 Chip Factory
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5536 题目: Chip Factory Time Limit: 18000/9000 MS ( ...
- 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 ...
- Chip Factory(01字典树)
Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others) ...
随机推荐
- (转)linux下控制帐户过期的多种方法
linux下控制帐户过期的方法:原文:http://blog.51cto.com/oldboy/1289144企业里一般给无人管理的角色账户或开发人员临时需求等可以设定账户有效期,提升安全!法一:添加 ...
- CentOS 6.2安装配置LAMP服务器(Apache+PHP5+MySQL)
准备篇: 1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp - ...
- h5点击区域和实际区域对不上
点击区域和实际区域对不上 然后点击后触发的其实是上面的区域,会导致事件触发错误
- easyUI filebox限定文件大小
转载自:https://www.2cto.com/kf/201701/574667.html 侵删 easyui1.5filebox控件中增加文件大小的验证规则 2017-01-07 09:22:0 ...
- 面向对象程序设计第四单元总结(UML系列)
2019面向对象程序设计第四单元总结 前言 本单元是面向对象程序设计课程的最后一个单元了,本单元是和UML模型相关,也就是说,我们需要正确理解UML模型的基础上,对构建出的UML模型进行解析,但是 ...
- Hive基础(1)
Hive基础(1) Hive的HQL(2) 1. Hive并不是分布式的,它独立于机器之外,类似于Hadoop的客户端. 2. 元数据和数据的区别,前者如表名.列名.字段名等. 3. Hive的三种安 ...
- HDU 4283 You Are the One (区间DP,经典)
题意: 某校举行一场非诚勿扰,给定一个出场序列,表示n个人的屌丝值,如果他是第k个出场的,他的不满意度为(k-1)*diao[i].为了让所有人的屌丝值之和更小,导演设置一个栈,可以将部分人装进栈中, ...
- 使用nodejs和Java访问远程服务器的服务
既然这篇文章用的是nodejs和Java访问远程服务器的服务,那么咱们先用另一门编程语言,SAP的ABAP(我日常工作使用得最多的编程语言)来开发一个服务吧. 这是我用ABAP编程语言实现服务的类:Z ...
- MovieReview—Despicable Me 3(神偷奶爸3)
Minions&Unicorn The film focuses on the story of Grew and the bastard Bled. A variety of ...
- 2015 ACM/ICPC Asia Regional Changchun Online Pro 1008 Elven Postman (BIT,dfs)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...