Codeforces Round #563 (Div. 2) DEhab and the Expected XOR Problem
Posted beafreeman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #563 (Div. 2) DEhab and the Expected XOR Problem相关的知识,希望对你有一定的参考价值。
D. Ehab and the Expected XOR Problem
Given two integers n and x, construct an array that satisfies the following conditions:
- for any element ai in the array, 1≤ai<2^n
- there is no non-empty subsegment with bitwise XOR equal to 0 or x,
- its length l should be maximized.
A sequence b is a subsegment of a sequence a if b can be obtained from a by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Input
The only line contains two integers n and x (1≤n≤18 1≤x<2^18).
Output
The first line should contain the length of the array l.
If l is positive, the second line should contain l space-separated integers a1, a2, ……, al (1≤ai<2^n) — the elements of the array a.
If there are multiple solutions, print any of them.
solution
这道题当时候在写的时候并不知道怎么写,题目大意就是要求子区间的异或和不能够0或者x,求最长的区间数字。1 #include<bits/stdc++.h> 2 #include<vector> 3 using namespace std; 4 long long n,x; 5 bool pd[2000010]; 6 int main() 7 cin>>n>>x; 8 memset(pd,0,sizeof pd); 9 long long cnm=(1<<n); 10 for (int i=0;i<cnm;i++) 11 if (!pd[i]) 12 pd[i^x]=1; 13 int ans=0; 14 for (int i=1;i<cnm;i++) 15 if (!pd[i]) 16 ans++; 17 cout<<ans<<endl; 18 int l=0; 19 for (int i=1;i<cnm;i++) 20 if (!pd[i]) 21 cout<<(i^l)<<‘ ‘; 22 l=i; 23 24
以上是关于Codeforces Round #563 (Div. 2) DEhab and the Expected XOR Problem的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #563 (Div. 2)
Codeforces Round #563 (Div. 2)
Codeforces Round 563 (Div. 2) 题解
Codeforces Round #563 (Div. 2) DEhab and the Expected XOR Problem
Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person
Codeforces Round #563 (Div. 2)C. Ehab and a Special Coloring Problem