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) ...
随机推荐
- 077 Combinations 组合
给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合.例如,如果 n = 4 和 k = 2,组合如下:[ [2,4], [3,4], [2,3], [1,2], [ ...
- Json规范
标准格式 书写使用首字母小写驼峰式 {" status":0 //状态 大于0代表正常.小于等于0代表异常 "message":"",/ ...
- openstack安装newton版本Nova部署(三)
一.控制节点安装部署Nova Nova 包含API(负责接收相应外部请求,支持OpenStackAPI,EC2API):cert:负责身份认证:schedule:用于云主机调度(虚拟机创建在哪台主机上 ...
- Spark Mllib里决策树回归分析使用.rootMeanSquaredError方法计算出以RMSE来评估模型的准确率(图文详解)
不多说,直接上干货! Spark Mllib里决策树二元分类使用.areaUnderROC方法计算出以AUC来评估模型的准确率和决策树多元分类使用.precision方法以precision来评估模型 ...
- When you want to give up, remember why you started.
When you want to give up, remember why you started.当你想要放弃的时候,请记住当初你为何而开始.
- 1、http简介
HTTP 简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传 ...
- CefSharp试用
Github地址: https://github.com/cefsharp/CefSharp 首先下载所有源代码下来 然后直接打开Sln 然后就可以直接调试WinForm.Wpf的Example了 注 ...
- OpenLayers 3 的 图层控制控件
openlayers3的control中没有提供默认的图层控制控件. 但是git上已经有造好的轮子,直接拿来用就可以了.地址 https://github.com/walkermatt/ol3-lay ...
- ListView适配器Adapter介绍与优化
一.ListView与Adapter的关系 ListView是Android开发过程中较为常见的组件之一,它将数据以列表的形式展现出来.一般而言,一个ListView由以下三个元素组成: 1.View ...
- 【转载】Alpha、Beta、RC、GA版本的区别
转自:http://www.blogjava.net/RomulusW/archive/2008/05/04/197985.html Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只 ...