题面

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.

题意

给两个数 \(n\) 和 \(x\),构造一个满足以下条件的序列:

·对任何序列中的元素 \(a_i\),\(1\leq a_i<2^n\)

·序列中没有非空连续子序列异或和为 \(0\) 或 \(x\)

·序列长度 \(l\) 应该最大

思路

思路比较巧妙,因为元素可重复不太好搞,就考虑构造一个答案序列 \(a\) 的异或前缀和 \(b\),且 \(b\) 满足任意 \(b_i \ xor \ b_j \ \not= \ x\) 或 \(0\)。

因为若 \(a \ xor \ b \ = \ c\),则 \(a \ xor \ c \ = \ b\),所以从 \(1\) 枚举到 \(2^n-1\) ,每次用可行的 \(i\) 数加入答案并排除 \(i \ xor \ x\) 这个数。

代码

/************************************************
*Author : lrj124
*Created Time : 2019.10.15.19:28
*Mail : 1584634848@qq.com
*Problem : cf1174d
************************************************/
#include <cstdio>
const int maxn = 1<<18;
int n,x,ans[maxn];
bool vis[maxn];
int main() {
//freopen("cf1174d.in","r",stdin);
//freopen("cf1174d.out","w",stdout);
scanf("%d%d",&n,&x);
vis[0] = vis[x] = true;
for (int i = 1;i < 1<<n;i++)
if (!vis[i]) {
vis[i^x] = true;
ans[++ans[0]] = i;
}
printf("%d\n",ans[0]);
for (int i = 1;i <= ans[0];i++) printf("%d ",ans[i]^(i ^ 1 ? ans[i-1] : 0));
return 0;
}

【CF1174D】 Ehab and the Expected XOR Problem - 构造的更多相关文章

  1. CF1174D Ehab and the Expected XOR Problem

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

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

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

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

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

  4. 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的 ...

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

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

  6. Codeforces Round #525 D - Ehab and another another xor problem /// 构造

    题目大意: 本题有两个隐藏起来的a b(1<=a,b<=1e30) 每次可 printf("? %d %d\n",c,d); 表示询问 a^c 与 b^d 的相对大小 ...

  7. 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 ...

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

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

  9. 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/ ...

随机推荐

  1. iconfont - 好用免费的图标库

    某里出品 打开首页???????搜索框在哪里 网站:点我

  2. 小程序开发全栈1.2/3/4组件、flex布局、样式

    1.2 组件 1.2.1 text组件 编写文本信息,类似于HTTP中的span 1.2.2 view组件 容器,类似于HTTP中的div 1.2.3 image组件 图片显示组件 1.3 页面fle ...

  3. WBF交易所如何使用二次验证码/谷歌身份验证器

    一般点账户名——设置——安全设置中开通虚拟MFA两步验证 具体步骤见链接  WBF交易所如何使用二次验证码/谷歌身份验证器 二次验证码小程序于谷歌身份验证器APP的优势 1.无需下载app 2.验证码 ...

  4. LaTeX公式学习

    简介 本文公式较多可能有加载较慢. 使用 LaTeX 的主要原因之一是它可以方便地排版公式.我们使用数学模式来排版公式. 公式 插入公式 可以用一对$来启用数学模式. 行中公式可以用如下方法: $数学 ...

  5. vue学习 `${HH}-${mm}-${dd}` 按键修饰符

    vue 有一种拼接字符串的规范写法 //键盘 Tab 键 上边的键 英文输入状态 然后采用类似EL表达式${变量}return `${}:${}:${}` //有时候我们经常在输入完密码之后,按回车E ...

  6. 使用Faker库生成模拟数据

    一.相关文档 该库在laravel框架中默认已经存在,无需手动进行安装.使用参考文档: https://packagist.org/packages/fzaninotto/faker 二.简单示例 & ...

  7. IO流——转换流、缓冲流

    一.转换流 1. OutputStreamWriter类 属于字符输出流,OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流中的字符编码成字节. 它的作 ...

  8. 控制语句—for循环、while循环

    for循环 基本结构: for(初始条件1:循环条件2:状态改变3){ 循环体4 } 运行流程:1-2-4-3-2-4 while循环 基本结构: var i=0 //初始条件 1 while(i&l ...

  9. Merging 和 Rebasing 的大比拼

    虽然 merging 和 rebasing 在 git 中相似时,但他们提供不同的功能.为了让你的历史尽可能的干净和完整,你应该知道以下几点. git rebase 命令已 神奇的 Git voodo ...

  10. 线程_GIL最简单的例子

    #解决多进程死循环 import multiprocessing def deadLoop(): while True: print("Hello") pass if __name ...