题中只有两个条件:任意区间异或值不等于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. WUST Oracle数据库 实验一实验二

    链接:https://pan.baidu.com/s/1hCzvTLzXhyItP2gD_69gzg 提取码:j68f 复制这段内容后打开百度网盘手机App,操作更方便哦

  2. c# asp.net 实现分页(pager)功能

    分页PagerHelper辅助类 using System;using System.Web; public class PagerHelper { #region 获取分页的Html代码 /// & ...

  3. 轻松搭建CAS 5.x系列(5)-增加密码找回和密码修改功能

    概述说明 CAS内置了密码找回和密码修改的功能: 密码找回功能是,系统会吧密码重置的连接通过邮件或短信方式发送给用户,用户点击链接后就可以重置密码,cas还支持预留密码重置的问题,只有回答对了,才可以 ...

  4. (七)Action之ActionContext(OGNL表达式的使用)

    一.ActionContext的重要性 struts中的数据都存放在ActionContext里,所以这部分是Action中的核心. ActionContext又称广义值栈,既然有广义值栈就有侠义值栈 ...

  5. JS基础_函数作用域练习

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. React/数据流

    “Props” 当 React 元素为用户自定义组件时,它会将 JSX 所接收的属性(attributes)转换为单个对象传递给组件,这个对象被称之为 “props”. props的只读性 组件无论是 ...

  7. PHP函数问题

    有时候,运行nginx和PHP CGI(PHP FPM)web服务的Linux服务器,突然系统负载上升,用top命令查看,很多phpcgi进程的CPU利用率接近100%后来通过跟踪发现,这种情况与PH ...

  8. 伪元素before和after本质

    之所以被称为伪元素,是因为他们不是真正的页面元素,html没有对应的元素,但所有的用法和表现行为和真正的页面元素是一样的,可以对其使用诸如页面元素一样的css样式,表面上看上去貌似页面的谋些元素,实际 ...

  9. Android获取设备唯一码

    String uuid = ""; String serial = null; String m_szDevIDShort = "35" + Build.BOA ...

  10. OpenStack kilo版(1) 部署环境

    硬件 VMware workstation虚拟机 Ubuntu14.04操作系统 虚拟机网络规划 管理网络: eth0, 桥接模式 10.0.0.0/24 外部网络: eth1, nat模式(需要关闭 ...