CF D. Ehab and the Expected XOR Problem 贪心+位运算

Posted guangheli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF D. Ehab and the Expected XOR Problem 贪心+位运算相关的知识,希望对你有一定的参考价值。

code: 

#include <bits/stdc++.h>          
#define N 1000000    
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std; 
int vis[N],b[N];           
void solve() 
{
    int n,m,i,j,cur=1,cnt=0;   
    memset(vis,0,sizeof(vis));   
    scanf("%d%d",&n,&m);   
    vis[m]=1;                  
    for(i=1;i<=(1<<n);++i) 
    {      
        while(vis[cur]) ++cur;        
        if((cur^b[cnt-1]) >= (1<<n)) break;                                                   
        b[++cnt]=cur;          
        vis[cur^m]=1;     
        ++cur;                                            
    }
    printf("%d
",cnt);     
    for(i=0;i<cnt;++i) printf("%d ",b[i]^b[i+1]);          
}
int main() 
{  
    int i,j,T; 
    // setIO("input");         
    solve();       
    return 0; 
}

  

以上是关于CF D. Ehab and the Expected XOR Problem 贪心+位运算的主要内容,如果未能解决你的问题,请参考以下文章

CF 862C Mahmoud and Ehab and the xor(异或)

Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string[二分]

D. Ehab and the Expected XOR Problem(Constructive & Xor)

CF1174D Ehab and the Expected XOR Problem - 构造

CF.862D.Mahmoud and Ehab and the binary string(交互 二分)

cf 1174 D Ehab and the Expected XOR Problem