Chip Factory

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 368    Accepted Submission(s): 202

Problem Description
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 n 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:

maxi,j,k(si+sj)⊕sk

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?

 
Input
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 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

 
Output
For each test case, please output an integer indicating the checksum number in a line.
 
Sample Input
2
3
1 2 3
3
100 200 300
 
Sample Output
6
400
 
Source
 
题意:给出一组n的数,问max((a[i]+a[j])^a[k]) i != j != k
分析:
有几种方法
1、现将a[i]+a[j]存起来,枚举k,在数据结构中查询。。。注意要去除ak的影响,我是用了主席树,其实可以用trie,这是最蠢的一种做法。。。就是我的做法。。。
2、将ak存起来,枚举ai,aj,注意到时间9s,同上的方法。比第一种快
3、暴力。。。。实在太猥琐了。。。居然没卡掉。。。。n^3暴力居然过了。。。
4、cheat做法。。。枚举前80%
 
 #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的更多相关文章

  1. 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

    House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  2. 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree

    Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  7. 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich

    Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  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. HDU 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. Tenth scrum meeting - 2015/11/4

    我们的项目开发已经渐渐进入了后期,每个模块都只剩下了一小块任务待做,同学们在做自己的模块的同时也开始对各个同学的模块进行合并. 其中最麻烦的就是视频播放模块与其他模块的合并了,由于该模块的实现需要添加 ...

  2. Hadoop 免密码登陆(ssh)

    record save here first [root@hadoop .ssh]# ssh-keygen -t rsa -P ''Generating public/private rsa key ...

  3. TCP协议漏洞影响大量Linux设备

    导读 本周三在得州奥斯丁举行的 USENIX 安全研讨会上,加州大学河滨分校研究生 Yue Cao 将报告一个严重的TCP协议边信道漏洞(PDF),该漏洞允许攻击者远程劫持任意两主机之间的会话.该漏洞 ...

  4. delphi 2007 远程调试

    Remote debugging lets you debug a RAD Studio application running on a remote computer. Once the remo ...

  5. poj1753枚举

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33670   Accepted: 14713 Descr ...

  6. dell idrac8 部署操作系统的方法

    1,打开虚拟控制台 2,“虚拟介质”->“连接虚拟介质”->“映射虚拟介质到CD”->(选择要安装的镜像文件)->“Map device” 3, “next boot”-> ...

  7. AWS AutoScaling

    origin_from: http://blog.csdn.net/libing_thinking/article/details/48327189 AutoScaling 是 AWS 比较核心的一个 ...

  8. 【Django】Django 文件下载最佳实践

    代码: from django.http import StreamingHttpResponse def big_file_download(request): # do something... ...

  9. HTML模仿桌面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Python操作Mysql实例代码教程在线版(查询手册)

    本文介绍了Python操作MYSQL.执行SQL语句.获取结果集.遍历结果集.取得某个字段.获取表字段名.将图片插入数据库.执行事务等各种代码实例和详细介绍,代码居多,是一桌丰盛唯美的代码大餐   实 ...