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


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.

1T1000
3n1000
0si109
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%
 
  1 #include <cstdio>
  2 #include <cstring>
  3 #include <cstdlib>
  4 #include <cmath>
  5 #include <ctime>
  6 #include <iostream>
  7 #include <map>
  8 #include <set>
  9 #include <algorithm>
 10 #include <vector>
 11 #include <deque>
 12 #include <queue>
 13 #include <stack>
 14 using namespace std;
 15 typedef long long LL;
 16 typedef double DB;
 17 #define MIT (2147483647)
 18 #define MLL (1000000000000000001LL)
 19 #define INF (1000000001)
 20 #define For(i, s, t) for(int i = (s); i <= (t); i ++)
 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i --)
 22 #define Rep(i, n) for(int i = (0); i < (n); i ++)
 23 #define Repn(i, n) for(int i = (n)-1; i >= (0); i --)
 24 #define mk make_pair
 25 #define ft first
 26 #define sd second
 27 #define puf push_front
 28 #define pub push_back
 29 #define pof pop_front
 30 #define pob pop_back
 31 #define sz(x) ((int) (x).size())
 32 #define clr(x, y) (memset(x, y, sizeof(x)))
 33 inline void SetIO(string Name)
 34 {
 35     string Input = Name + ".in";
 36     string Output = Name + ".out";
 37     freopen(Input.c_str(), "r", stdin);
 38     freopen(Output.c_str(), "w", stdout);
 39 }
 40 
 41 inline int Getint()
 42 {
 43     char ch = ' ';
 44     int Ret = 0;
 45     bool Flag = 0;
 46     while(!(ch >= '0' && ch <= '9'))
 47     {
 48         if(ch == '-') Flag ^= 1;
 49         ch = getchar();
 50     }
 51     while(ch >= '0' && ch <= '9')
 52     {
 53         Ret = Ret * 10 + ch - '0';
 54         ch = getchar();
 55     }
 56     return Ret;
 57 }
 58 
 59 const int N = 1010, M = 1000010, Dep = 32;
 60 struct SegmentType
 61 {
 62     int Child[2], Sum;
 63     #define Lc(x) (Seg[x].Child[0])
 64     #define Rc(x) (Seg[x].Child[1])
 65     #define Child(x, y) (Seg[x].Child[y])
 66     #define Sum(x) (Seg[x].Sum)
 67 } Seg[(M+N)*Dep];
 68 int Tot;
 69 int n, Arr[N];
 70 int Cnt[M], Length;
 71 int Ans;
 72 
 73 inline void Solve();
 74 
 75 inline void Input()
 76 {
 77     int TestNumber = Getint();
 78     while(TestNumber--)
 79     {
 80         n = Getint();
 81         For(i, 1, n) Arr[i] = Getint();
 82         Solve();
 83     }
 84 }
 85 
 86 inline void Init(int x) {
 87     clr(Seg[x].Child, 0), Sum(x) = 0;
 88 }
 89 
 90 inline void Insert(int Val, int x, int Depth)
 91 {
 92     Sum(x)++;
 93     if(Depth < 0) return;
 94     int Type = (Val & (1 << Depth)) > 0;
 95     if(!Child(x, Type)) {
 96         Child(x, Type) = ++Tot;
 97         Init(Child(x, Type));
 98     }
 99     Insert(Val, Child(x, Type), Depth-1);
100 }
101 
102 inline int Work(int Val, int x, int Depth)
103 {
104     if(!x) return 0;
105     if(Depth < 0) return Sum(x);
106     int Type = (Val & (1 << Depth)) > 0;
107     if(Type) return Sum(Lc(x)) + Work(Val, Rc(x), Depth - 1);
108     return Work(Val, Lc(x), Depth - 1);
109 }
110 
111 inline void Query(int Val, int x, int Depth, int &Ret)
112 {
113     if(Depth < 0) return;
114     int Type = (Val & (1 << Depth)) > 0;
115     if(Child(x, Type ^ 1))
116     {
117         int p1 = Ret;
118         p1 |= (1 << Depth) * (Type ^ 1);
119         p1 = p1 - Val - 1;
120         int A = Work(p1, 2, 30);
121         int p2 = Ret;
122         p2 |= (1 << Depth) * (Type ^ 1);
123         p2 |= (1 << Depth) - 1;
124         p2 = p2 - Val;
125         int B = Work(p2, 2, 30);
126         int p = B - A;
127         if(Val > p1 && Val <= p2) p--;
128         if(Sum(Child(x, Type ^ 1)) - p > 0)
129         {
130             Ret |= (1 << Depth) * (Type ^ 1);
131             Query(Val, Child(x, Type ^ 1), Depth - 1, Ret);
132             return;
133         }
134     }
135     Ret |= (1 << Depth) * Type;
136     Query(Val, Child(x, Type), Depth - 1, Ret);
137 }
138 
139 inline void Solve()
140 {
141     Tot = 2, Length = 0;
142     Init(1), Init(2), Init(0);
143     For(i, 1, n)
144     {
145         For(j, i + 1, n)
146         {
147             Cnt[++Length] = Arr[i] + Arr[j];
148             Insert(Cnt[Length], 1, 30);
149         }
150         Insert(Arr[i], 2, 30);
151     }
152     
153     Ans = 0;
154     for(int i = 1; i <= n; i++)
155     {
156         int x = 0;
157         Query(Arr[i], 1, 30, x);
158         Ans = max(Ans, x ^ Arr[i]);
159     }
160     printf("%d\n", Ans);
161 }
162 
163 int main()
164 {
165     Input();
166     //Solve();
167     return 0;
168 }
View Code

 

posted @ 2015-11-04 21:30  yanzx6  阅读(262)  评论(0编辑  收藏  举报