题中只有两个条件:任意区间异或值不等于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. mysql中char和varchar区别

    char是一种固定长度的类型,varchar则是一种可变长度的类型  char(M)类型的数据列里,每个值都占用M个字节,如果某个长度小于M,MySQL就会在它的右边用空格字符补足.(在检索操作中那些 ...

  2. zookeeper-waches

    1. 设置watches data watches: getData() exist() child watches: getChildren() 2. 触发watches setData(): da ...

  3. 【闭包】Pants On Fire

    Pants On Fire 题目描述 Donald and Mike are the leaders of the free world and haven’t yet (after half a y ...

  4. Typora 的使用

    一. Typora的markdown语法 1.标题 使用简单的ctr+数字健,就可以快速完成各种级别的标题 #一阶标题 或者快捷键Ctrl+1 ##二阶标题 或者快捷键Ctrl+2 ##二阶标题 或者 ...

  5. (六)Activiti之实现学生请假流程

    一.实现学生请假流程 1.1 用activiti插件生成bpmn和png文件 1.2 部署流程定义 package com.shyroke.activiti.firstActiviti; import ...

  6. (二)Redis之Jedis概念和HelloWorld实现以及JedisPool的使用

    一.Jedis概念 实际开发中,我们需要用Redis的连接工具连接Redis然后操作Redis, 对于主流语言,Redis都提供了对应的客户端: 官网:https://redis.io/clients ...

  7. redis的下载和安装

    下载 http://download.redis.io 这里我们以redis的5.0.5版本和centos7环境为基础介绍 安装 1.将下载的redis-5.0.5.tar.gz文件上传到linux上 ...

  8. MySQL 的COUNT(x)性能怎么样?

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! x 可以代表: 主键id.字段.1.* 0 说明 对于count(主键id)来说 innodb引擎会遍历整张表,把每一行的 ...

  9. win中使用curl上传文件报错

    今天晚上复现“WordPress插件Easy WP SMTP反序列化漏洞”时,需要使用curl上传文件,我又用的windows环境,一直出错 curl: (26) couldn't open file ...

  10. c去除空格 小写转大写

    int isalnum(int c); //字母或数字 int isalpha(int c); //英文字母 int isascii(int c); //ASCII 码字符(0 到127) int i ...