地址:https://codeforces.com/contest/1174/problem/D
思路:这题秒啊,题目要求构造数组a[],要求其子串异或不能为0或x,那么它的前缀异或数组d[],则d[i]的特点为两两不相等且d[i]不为0或x,这样就转换为求 前缀异或数组d[],而d[]可以遍历 [1-2^n) ,或取 i,则 异或值 i^x 不能取,这样就能得到d[],再由d[]转换为a[]即可
Code:
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAX_S=1e6+5;
int n;
LL s;
LL res[MAX_S];
bool boo[MAX_S];
int main()
{
ios::sync_with_stdio(false);
cin>>n>>s;
int ans=0;
n=(1<<n);
for(int i=1;i<n;++i)
if(!boo[i]&&i!=s){
res[ans++]=i;
boo[s^i]=true;
}
cout<<ans<<endl;
for(int i=ans-1;i>=1;--i)
{
res[i]^=res[i-1];
cout<<res[i]<<" ";
}
if(ans) cout<<res[0]<<endl;
return 0;
}