hdu5536(01字典树)

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 ii

-th chip produced this day has a serial number sisi

.

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)⊕skmaxi,j,k(si+sj)⊕sk

which i,j,ki,j,k

are three different integers between 11

and nn

. And ⊕⊕

is symbol of bitwise XOR.

Can you help John calculate the checksum number of today? InputThe first line of input contains an integer TT

indicating the total number of test cases.

The first line of each test case is an integer nn

, indicating the number of chips produced today. The next line has nn

integers s1,s2,…,sns1,s2,…,sn

, separated with single space, indicating serial number of each chip.

1≤T≤10001≤T≤1000

3≤n≤10003≤n≤1000

0≤si≤1090≤si≤109

There are at most 1010

testcases with n>100n>100

OutputFor 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

1.暴力竟然能过(mmp)暴力出奇迹。。
2.正解:01字典树,附上神仙的博客~
https://www.cnblogs.com/letlifestop/p/10262761.html
下面是01字典树

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int sto[N][4],tot,a[1005];
long long flag[N],com[N];
void init()
{
   
    for(int i=0;i<=tot;i++)
    {
   
        flag[i]=0;
        com[i]=0;
        for(int j=0;j<3;j++)
        {
   
            sto[i][j]=0;
        }
    }
    tot=0;
}
void add(long long a)
{
   
    int u=0;
    for(int i=32;i>=0;i--)
    {
   
        int tmp=(a>>i)&1;
        if(sto[u][tmp]==0)
            sto[u][tmp]=++tot;
        flag[sto[u][tmp]]++;
        u=sto[u][tmp];
    }
    com[u]=a;
}
void Erase(long long a)
{
   
    int u=0;
    for(int i=32;i>=0;i--)
    {
   
        int tmp=(a>>i)&1;
        flag[sto[u][tmp]]--;
        u=sto[u][tmp];
    }
}
long long query(long long a)
{
   
    int u=0;
    for(int i=32;i>=0;i--)
    {
   
        int tmp=(a>>i)&1;
        if(sto[u][tmp^1]>0)
        {
   
            if(flag[sto[u][tmp^1]]>0)
                u=sto[u][tmp^1];
            else
                u=sto[u][tmp];
        }
        else
        {
   
            if(flag[sto[u][tmp]]>0)
                u=sto[u][tmp];
            else
                u=sto[u][tmp];
        }
    }
    return com[u]^a;///返回异或值
}
int main()
{
   
    int t,n,m,i;
    tot=0;
    scanf("%d",&t);
    while(t--)
    {
   
        init();
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
   
            scanf("%lld",&a[i]);
            add(a[i]);
        }
        long long maxx=0;
        for(int i=1;i<=n;i++)
        {
   
            Erase(a[i]);
            for(int j=i+1;j<=n;j++)
            {
   
                Erase(a[j]);
                maxx=max(query(a[i]+a[j]),maxx);
                add(a[j]);
            }
            add(a[i]);
        }
        cout<<maxx<<'\n';
    }
    return 0;
}

全部评论

相关推荐

群星之怒:1.照片可以换更好一点的,可以适量P图,带一些发型,遮住额头,最好穿的正式一点,可以适当P图。2.内容太少。建议添加的:求职意向(随着投递岗位动态更改);项目经历(内容太少了建议添加一些说明,技术栈:用到了什么技术,还有你是怎么实现的,比如如何确保数据传输稳定的,角色注册用到了什么技术等等。)项目经历是大头,没有实习是硬伤,如果项目经理不突出的话基本很难过简历筛。3.有些内容不必要,比如自我评价,校内实践。如果实践和工作无关千万别写,不如多丰富丰富项目。4.排版建议:建议排版是先基础信息,然后教育背景(要突出和工作相关的课程),然后专业技能(一定要简短,不要长篇大论,写你会什么,会的程度就可以),然后是项目经历(一定要详细,占整个简历一定要超过一半,甚至超过百分之70都可以)。最后如果有一部分空白的话可以填补上校内获得的专业相关的奖项,没有就写点校园经历和自我评价。5.技术一定要够硬,禁得住拷打。还有作息尽量保证正常,不要太焦虑。我24双非本科还是非科班,秋招春招各找了一段实习结果都没有转正,当时都想噶了,最后6月份在校的尾巴也找到一份工作干到现在,找工作有时很看运气的不要急着自我否定。 加油
点赞 评论 收藏
分享
野猪不是猪🐗:现在的环境就是这样,供远大于求。 以前卡学历,现在最高学历不够卡了,还要卡第一学历。 还是不够筛,于是还要求得有实习、不能有gap等等... 可能这个岗位总共就一个hc,筛到最后还是有十几个人满足这些要求。他们都非常优秀,各方面都很棒。 那没办法了,看那个顺眼选哪个呗。 很残酷,也很现实
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务