给两个数 $ n $ 和 $ x $,构造一个满足以下条件的序列:
构造前缀和序列 \(s_i = \oplus_{j=1}^i a_i\),每次暴力找一个 \([1,2^n)\) 的数,使得 \(s_i\) 没有出现过即可
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n,x,b[N],a[N],top;
signed main() {
ios::sync_with_stdio(false);
cin>>n>>x;
top=1;
b[0]=b[x]=1;
while(true) {
for(int i=1;i<1<<n;i++) {
if(b[a[top-1]^i]==0) {
a[top]=a[top-1]^i;
b[a[top]]=1;
b[a[top]^x]=1;
break;
}
}
if(a[top]) ++top;
else break;
}
cout<<top-1<<endl;
for(int i=1;i<=top-1;i++) cout<<(a[i]^a[i-1])<<" ";
}
[CF1174D] Ehab and the Expected XOR Problem - 构造
原文:https://www.cnblogs.com/mollnn/p/12826588.html