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) ...
随机推荐
- shell 获得调用的python脚本的print值和错误log
1. shell 获得调用的python脚本的print值 python test.py > out.log 2.shell 获得调用的python脚本的错误log python test.py ...
- C#里边的控件缩写大全(比较规范)
标准控件1 btn Button 2 chk CheckBox 3 ckl CheckedListBox 4 cmb ComboBox 5 dtp DateTimePicker 6 lbl Label ...
- Webstorm 激活
注册时,在打开的License Activation窗口中选择“License server”,在输入框输入下面的网址: http://idea.iteblog.com/key.php 点击:Acti ...
- Ionic开发-常用插件安装
cordova plugin add cordova-plugin-nativestoragecordova plugin add cordova-plugin-devicecordova plu ...
- paas相关,添加ing
1. docker 构建镜像,docker build -t image_name:version dockerfilePath.使用镜像启动一个docker容器,docker run --name ...
- css3响应式图片
响应式图片指用户代理根据输出设备的分辨率不同加载不同类型的图片,不会造成带宽的浪费. 同时,在改变输出设备类型或分辨率时,能及时加载对应类型的图片. 常用的实现方式: 1.用srcset和size ...
- rest_framework序列化组件
一.Django自带的序列化组件 ==>对象序列化成json格式的字符串 from django.core import serializers from django.core import ...
- 【简抄】h5 新增的几个背景属性和文本属性
一.背景图像显示: ①background-size:规定背景图像的大小: 值:像素值.百分比.auto.cover.contain ②background-origin :规定背景图像的起始位置: ...
- 安卓中Paint类和Canvas类的方法汇总
Paint类的常用的方法 1.setColor方法,用于设置画笔的颜色,public void setColor(int color)//参数color为颜色值,也可以使用Color类定义的颜色Col ...
- 科学效法自然:微软研究人员测试AI控制的滑翔机
编者按:正如一颗苹果砸出了万有引力,自然界所有存在的事物和现象都有其科学合理的一面,小小的鸟儿也能够给科学带来丰富的灵感和启示. 最近,微软研究人员从自然出发,研究鸟类能够自由停留在空中的科学原理,并 ...