2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 368 Accepted Submission(s): 202
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:
which i,j,k are three different integers between 1 and n. And ⊕ is symbol of bitwise XOR.
Can you help John calculate the checksum number of today?
The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n 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
3
1 2 3
3
100 200 300
400
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define MLL (1000000000000000001LL)
#define INF (1000000001)
#define For(i, s, t) for(int i = (s); i <= (t); i ++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i --)
#define Rep(i, n) for(int i = (0); i < (n); i ++)
#define Repn(i, n) for(int i = (n)-1; i >= (0); i --)
#define mk make_pair
#define ft first
#define sd second
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define sz(x) ((int) (x).size())
#define clr(x, y) (memset(x, y, sizeof(x)))
inline void SetIO(string Name)
{
string Input = Name + ".in";
string Output = Name + ".out";
freopen(Input.c_str(), "r", stdin);
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
char ch = ' ';
int Ret = ;
bool Flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') Flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
Ret = Ret * + ch - '';
ch = getchar();
}
return Ret;
} const int N = , M = , Dep = ;
struct SegmentType
{
int Child[], Sum;
#define Lc(x) (Seg[x].Child[0])
#define Rc(x) (Seg[x].Child[1])
#define Child(x, y) (Seg[x].Child[y])
#define Sum(x) (Seg[x].Sum)
} Seg[(M+N)*Dep];
int Tot;
int n, Arr[N];
int Cnt[M], Length;
int Ans; inline void Solve(); inline void Input()
{
int TestNumber = Getint();
while(TestNumber--)
{
n = Getint();
For(i, , n) Arr[i] = Getint();
Solve();
}
} inline void Init(int x) {
clr(Seg[x].Child, ), Sum(x) = ;
} inline void Insert(int Val, int x, int Depth)
{
Sum(x)++;
if(Depth < ) return;
int Type = (Val & ( << Depth)) > ;
if(!Child(x, Type)) {
Child(x, Type) = ++Tot;
Init(Child(x, Type));
}
Insert(Val, Child(x, Type), Depth-);
} inline int Work(int Val, int x, int Depth)
{
if(!x) return ;
if(Depth < ) return Sum(x);
int Type = (Val & ( << Depth)) > ;
if(Type) return Sum(Lc(x)) + Work(Val, Rc(x), Depth - );
return Work(Val, Lc(x), Depth - );
} inline void Query(int Val, int x, int Depth, int &Ret)
{
if(Depth < ) return;
int Type = (Val & ( << Depth)) > ;
if(Child(x, Type ^ ))
{
int p1 = Ret;
p1 |= ( << Depth) * (Type ^ );
p1 = p1 - Val - ;
int A = Work(p1, , );
int p2 = Ret;
p2 |= ( << Depth) * (Type ^ );
p2 |= ( << Depth) - ;
p2 = p2 - Val;
int B = Work(p2, , );
int p = B - A;
if(Val > p1 && Val <= p2) p--;
if(Sum(Child(x, Type ^ )) - p > )
{
Ret |= ( << Depth) * (Type ^ );
Query(Val, Child(x, Type ^ ), Depth - , Ret);
return;
}
}
Ret |= ( << Depth) * Type;
Query(Val, Child(x, Type), Depth - , Ret);
} inline void Solve()
{
Tot = , Length = ;
Init(), Init(), Init();
For(i, , n)
{
For(j, i + , n)
{
Cnt[++Length] = Arr[i] + Arr[j];
Insert(Cnt[Length], , );
}
Insert(Arr[i], , );
} Ans = ;
for(int i = ; i <= n; i++)
{
int x = ;
Query(Arr[i], , , x);
Ans = max(Ans, x ^ Arr[i]);
}
printf("%d\n", Ans);
} int main()
{
Input();
//Solve();
return ;
}
2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory的更多相关文章
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 5536 Chip Factory (01 Trie)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5536 题面; Chip Factory Time Limit: 18000/9000 MS (Java/O ...
- HDU 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
随机推荐
- java笔记--关于int和byte[]的转换
关于int和byte[]数组的转换 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3891747.html "谢谢-- 众所 ...
- [Effective JavaScript 笔记]第23条:永远不要修改arguments对象
arguments对象并不是标准的Array类型的实例.arguments对象不能直接调用Array方法. arguments对象的救星call方法 使得arguments可以品尝到数组方法的美味,知 ...
- Linux下读取默认MAC地址
导读MAC(Media Access Control,介质访问控制)计算机通过它来定义并识别网络设备的位置.在嵌入式linux学习中不可避免也会遇到MAC,本文主要描述了如何通过操作OTP来读取嵌入式 ...
- L17 怎么向应用程序商店提交应用
原地址:https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/ApplicationD ...
- 【转】INSTALL_FAILED_NO_MATCHING_ABIS 的解决办法
在Android模拟器上安装apk的时候出现 INSTALL_FAILED_NO_MATCHING_ABIS 这个错误提示的解决办法. 是由于使用了native libraries .该nativ ...
- 关于ubuntu配置静态IP 无法正常上网的解决方案
在ubuntu中配置静态IP后无法正常上网. 解决: 1.在终端执行 vim /etc/network/interfaces 在文件中加入如下内容,网关要写上,我开始一直无法上网就是因为没有配置网关 ...
- 【云计算】Docker删除名称为none的Image镜像
先上删除命令: docker images|grep none|awk '{print $3 }'|xargs docker rmi docker强制批量删除none的image镜像 真是有段时间 ...
- Java for LeetCode 174 Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- hdu 1425 sort 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 常规的方法是对输入的数从大到小进行排序(可以用sort或qsort),然后输出前m大的数. 不过 ...
- java关闭流,解压缩后的清除
关闭流文件和file文件的时候,先打开的后关闭,后打开的先关闭,实在不行调用system.jc()方法