HDU 5536 Chip Factory

Posted 自为

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5536 Chip Factory相关的知识,希望对你有一定的参考价值。

Chip Factory

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


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 s技术分享图片i技术分享图片技术分享图片 .

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:
max技术分享图片i,j,k技术分享图片(s技术分享图片i技术分享图片+s技术分享图片j技术分享图片)s技术分享图片k技术分享图片技术分享图片

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 s技术分享图片1技术分享图片,s技术分享图片2技术分享图片,..,s技术分享图片n技术分享图片技术分享图片 , separated with single space, indicating serial number of each chip.

1T1000技术分享图片
3n1000技术分享图片
0s技术分享图片i技术分享图片10技术分享图片9技术分享图片技术分享图片
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
 

 

Recommend
hujie   |   We have carefully selected several similar problems for you:  6263 6262 6261 6260 6259 
 
 
读不懂英语好吃亏啊。
一开始一直在想前面的$s_i+s_j$怎么搞。
后来看了一下输入,这么不就是个逗比题么。。
$s_i+s_j$只要暴力枚举就好,建一颗01Trie树,查询最大的时候优先走不一样的
查询之前先把$s_i,s_j$删除
查完之后再加进去
 
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=1e6+10;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}
    return x*f;
}
#define debug(x) printf("%d",x);
struct node
{
    int val,ch[2];
    node(){val=ch[0]=ch[1]=0;}
    void clear(){val=ch[0]=ch[1]=0;}
}T[MAXN];
int a[MAXN],root=0,tot=0;
void Insert(int v)
{
    int now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        if(!T[now].ch[opt]) 
            T[now].ch[opt]=++tot;
        now=T[now].ch[opt];
        T[now].val++;
     }
}
void Delet(int v)
{
    int now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        now=T[now].ch[opt];
        T[now].val--;
     }
}
int Query(int v)
{
    int ans=0,now=root;
    for(int i=31;i>=0;i--)
    {
        int opt=(v&(1<<i))?1:0;
        if(T[T[now].ch[opt^1]].val) 
            ans+=1<<i,now=T[now].ch[opt^1];
        else 
            now=T[now].ch[opt];
    }
    return ans;
}
int main()
{
    freopen("a.in","r",stdin);
    int Test=read();
    while(Test--)
    {
        int N=read();
        for(int i=1;i<=N;i++) a[i]=read();
        for(int i=1;i<=4*N;i++) 
            T[i].clear();
        for(int i=1;i<=N;i++) 
            Insert(a[i]);
        int ans=0;
        for(int i=1;i<=N;i++)
        {
            for(int j=1;j<i;j++)
            {
                Delet(a[i]);Delet(a[j]);
                ans=max(ans,Query(a[i]+a[j]));
                Insert(a[i]);Insert(a[j]);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

以上是关于HDU 5536 Chip Factory的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5536 Chip Factory

HDU 5536--Chip Factory(暴力)

HDU 5536 Chip Factory

HDU5536 Chip Factory

HDU - 5536 Chip Factory 字典树的删除

hdu 5536 Chip Factory 字典树+bitset 铜牌题