题中只有两个条件:任意区间异或值不等于0或m.

如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等.

而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m.

即 $xor[i]$^$xor[j]!=m$, $\Rightarrow$ m^xor[j] 这个异或前缀就不可以再次出现了.

用一个数组标记一下就好了~

#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\n",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 贪心+位运算的更多相关文章

  1. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

  2. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  3. CF1174D Ehab and the Expected XOR Problem

    思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...

  4. CF1174D Ehab and the Expected XOR Problem(二进制)

    做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...

  5. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  6. cf1088D Ehab and another another xor problem (构造)

    题意:有两数a,b,每次你可以给定c,d询问a xor c和b xor d的大小关系,最多询问62次($a,b<=2^{30}$),问a和b 考虑从高位往低位做,正在做第i位,已经知道了a和b的 ...

  7. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  8. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  9. Codeforces.1088D.Ehab and another another xor problem(交互 思路)

    题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...

随机推荐

  1. TZOJ2882: 美食节之感恩父母

    #include<stdio.h> int main() { ],b[],i,j,max,m,t1,t2,t3; while(scanf("%d",&m),m) ...

  2. (一)easyUI之树形网络

    树形网格(TreeGrid)可以展示有限空间上带有多列和复杂数据电子表 一.案例一:按tree的数据结构来生成 前台 <%@ page language="java" con ...

  3. [转载]JDK、SDK、J2EE、J2SE、J2ME的区别

    [转载]JDK.SDK.J2EE.J2SE.J2ME的区别 来源: https://www.cnblogs.com/liangyihui/p/5905875.html Java的名词真的是多啊 JDK ...

  4. linux物理地址和虚拟地址定义

    线性地址(Linear Address) 是逻辑地址到物理地址变换之间的中间层 如果启用了分页机制,那么线性地址可以再经过变换以产生一个物理地址:如果没有启用分页机制,那么线性地址直接就是物理地址 分 ...

  5. c#模拟鼠标左键单击

    [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern int mouse_e ...

  6. EF方式增加数据

             单条记录添加 第一种方式: public void AddRegion() { using(Northwind db = new Northwind()) { Region regi ...

  7. MyBaties --day1

    今天就来聊聊这个东西 今天的主角相信大家也看到了 MyBaties  是个什么东东 它有什么作用?怎么用?好不好用今天来说说 .说到MyBaties 就不得不谈到JDBC大家可能都知道 JDBC用来操 ...

  8. springboot系列(五) 静态资源处理

    转载:https://www.cnblogs.com/magicalSam/p/7189476.html 1.静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户通过浏览器直接读取. ...

  9. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  10. less运算

    less里面是可以有运算的,任何数字,颜色或者变量都可以参与与暗算,运算应该被包裹在括号中.   @test_width:300px; .box_width{ width: (@test_width ...