思路:

使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x。

实现:

 #include <bits/stdc++.h>
using namespace std;
int vis[ << ];
int main()
{
int n, x;
while (cin >> n >> x)
{
memset(vis, , sizeof vis);
vector<int> v;
if (x >= ( << n))
{
for (int i = ; i < ( << n); i++) v.push_back(i);
}
else
{
for (int i = ; i < ( << n); i++)
{
if (i == x) continue;
else if (!vis[i]) { v.push_back(i); vis[i ^ x] = ; }
}
}
cout << v.size() << endl;
if (!v.empty())
{
cout << v[] << " ";
for (int i = ; i < (int)v.size(); i++) cout << (v[i - ] ^ v[i]) << " ";
cout << endl;
}
}
return ;
}

CF1174D Ehab and the Expected XOR Problem的更多相关文章

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

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

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

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

  3. CF D. Ehab and the Expected XOR Problem 贪心+位运算

    题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...

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

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

  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. [poj1737]Connected Graph(连通图计数)

    题意:输出题中带有$n$个标号的图中连通图的个数. 解题关键: 令$f(n)$为连通图的个数,$g(n)$为非联通图的个数,$h(n)$为总的个数. 则$f(n) + g(n) = h(n)$ 考虑标 ...

  2. JavaScript学习系列6 -- JavaScript中的垃圾回收(内存释放)

    程序开发中,涉及到的内存生命周期基本是一样的,分为以下三步 1. 分配需要的内存 2. 使用分配到的内存 3. 释放其内存    ----什么时候释放内存,以及需要释放哪些变量的内存, 就是垃圾回收机 ...

  3. NPM run start使用本地的http-server

    在项目开发过程中,Visual Studio 2015 一个Solution中有一个前端项目 Myproject.FrontEnd,我们使用node.js, npm来进行管理 在这个项目中,有一个pa ...

  4. bash字符串匹配

    #!/bin/shfoo(){    local basedir=$1    local all_entries=`ls -c`    for entry in $all_entries    do ...

  5. Flash builder发布Air程序时设备配置文件supportedProfiles的配置

    1. 发布的程序:需要访问本地进程,那么只能发布为exe程序才可以.   此时supportedProfiles 配置为 extendedDesktop desktop   desktop保证能发布a ...

  6. SQL Server 查询分析器提供的所有快捷方式(快捷键)

    SQL Server程序员经常要在SSMS(SQL Server Management Studio)或查询分析器(2000以前)中编写T-SQL代码.以下几个技巧,可以提升工作效率. 以下说明以SS ...

  7. cinder服务状态up/down的源码梳理

    基于ocata版本的,源码梳理 1)用户输入cinder service-list命令行,查看cinder服务的状态时,cinder的入口函数为cinder/api/contrib/services. ...

  8. Docker Flie

    七.Docker File .dockeringore:打包忽略的文件列表,每行写一个文件的路径,可使用通配符 FROM指令:指定基础镜像 FROM <repository>[:<t ...

  9. 入侵检测系统 - ossec

    http://www.cnblogs.com/zlslch/p/8512757.html

  10. EIGRP-1-EIGRP的基础和演变

    值得一提的是,在2013年,Cisco决定开放EIGRP的定义,并将其发布为IETFInternet草案,即RFC的前身:文档名称为draft-savage-eigrp.从此,基本的EIGRP不再是机 ...