The XOR Largest Path

The XOR Largest Path

The XOR Longest Path
题意:给定n个数Ai,问两个数A进行XOR后的最大值

倒叙建trie,每次到p的时候对相对位置进行判断,如果有就从相对位置出发

int n;
int trie[maxn*32+5][2],tot=1;
void inser(LL a){//trie插入
    int p=1;
    LL ch=1ll;
    for(LL i=32;i>=0;i--){
        ch=a>>i&1ll;
        if(trie[p][ch]==0)trie[p][ch]=++tot;
        p=trie[p][ch];
    }
}
LL sear(LL a){
    int p=1;
    LL ch=1ll,ans=0ll;
    for(LL i=32;i>=0;i--){
        ch=a>>i&1ll;
        if(trie[p][ch^1]){//相对位置
            p=trie[p][ch^1];
            ans|=1<<i;
        }else{
            p=trie[p][ch];
        }
    }
    return ans;
}
LL A[maxn];
int main(){
    int n;
    sci(n);
    LL res=0;
    for(int i=1;i<=n;i++){
        scl(A[i]);
        inser(A[i]);
        res=max(res,sear(A[i]));
    }
    cout<<res<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值