首页 > 其他分享 >一本通1472:The XOR Largest Pair

一本通1472:The XOR Largest Pair

时间:2022-12-01 23:12:12浏览次数:42  
标签:ch XOR int Largest tot 1472 ans Pair include

 

 将数字看为01串插入字典树 ,  贪心每次尝试走01串的相反的路

#include<iostream>
#include <algorithm>
#include <cstring>
using namespace std;
 const int N=1e5+4;
 int ch[N*32][2],tot;
 int ans;
 void insert(int x){
     int i,c,u=1;
     
     for(i=31;i>=0;i--){
          c=(x>>i)&1;
         if(ch[u][c]==0){
             ch[u][c]=++tot; 
         }
         u=ch[u][c];
     }
 }
 void find(int x){
     int i,c,u=1;
     int t=0;
     for(i=31;i>=0;i--){
         c= (x>>i)&1; c=c^1;
         
         if(ch[u][c]) u=ch[u][c],t=t*2+1;
         else u=ch[u][c^1],t=t*2;
     }
     ans=max(ans,t);
 }
 main(){
     int n,i,x; cin>>n;
     tot=1;
     for(i=1;i<=n;i++){
         cin>>x; find(x); insert(x);
     }
     cout<<ans;
 }

 

标签:ch,XOR,int,Largest,tot,1472,ans,Pair,include
From: https://www.cnblogs.com/towboa/p/16943089.html

相关文章

  • 数据结构(1) pair和map使用
         #include<iostream>#include<thread>#include<map>#include<algorithm>#include<vector>#ifdeflniux#include<unistd.h>//usleep(100......
  • 异或(xor)的性质
    一点性质(1)xxory=zxxorz=y(2)xor是一个不带进位的二进制加法.实际例子已知\(n\)个同学的学号,现在有一场活动,来了\(n-1\)个同学,他们每个人都把自己的学号写......
  • 『题解』Codeforces 1758B XOR = Average
    Description构造一个\(a\)序列,使\(a_1\oplusa_2\oplusa_3\oplus\cdots\oplusa_n=\dfrac{sum(a)}{n}\)。Solution第一眼看到这道题,我想到的是分情况讨论。......
  • ARC127 Sum of Min of Xor
    可以发现\(a_i\bigoplusb_i\bigoplusa_j\bigoplusb_j\)为\(1\)的位置,是\(a_i\bigoplusa_j\)与\(b_i\bigoplusb_j\)不同的位置。设\(c_i=a_i\bigopl......
  • XOR Sum of Arrays
    section>ProblemStatementForsequences$B=(B_1,B_2,\dots,B_M)$and$C=(C_1,C_2,\dots,C_M)$,eachoflength$M$,consistingofnon-negativeintegers,lettheX......
  • [数学记录]arc137D Prefix Xors
    FWT/高维前缀和入门题。题意:给定一个数列\(a\),每次迭代把原数组替代为前缀异或和数组,求经过\(1-m\)次操作后\(a_n\)的值。\(n\leq10^6\)。首先,无论是手推找规律还......
  • Mysql : 出现Table ‘./mysql/proc’ is marked as crashed and should be repaired
    今天升级脚本出现的问题:Table‘./mysql/proc’ismarkedascrashedandshouldberepaired一般这种表崩溃的问题出现在mysql异常停止,或者使用kill-9命令强行杀掉进......
  • 哈希算法学习笔记 I:XOR hashing
    咕咕中,两天后填坑。CF1175F.TheNumberofSubpermutations求一个序列中是排列的子串数量。CF1746F.Kazaee多组询问,求一个序列的\([l,r]\)段是否为排列。......
  • 【做题笔记】CF1528B Kavi on Pairing Duty
    ProblemCF1528BKavionPairingDuty题目大意:在数轴上有\(2n\)个点,相邻两个点的距离为\(1\)。现在要将这些点两两匹配成\(n\)个圆弧,要求任意两个圆弧要么等长,要么......
  • KeyValuePair 和 Dictionary 的关系
    https://www.likecs.com/show-205081943.html#sc=466.6666564941406KeyValuePair 和 Dictionary 的关系1、KeyValuePair    a、KeyValuePair是一个结构体(struc......