题面

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. 深入掌握K8S Pod

    k8s系列文章: 什么是K8S K8S configmap介绍 Pod是k8s中最小的调度单元,包含了一个"根容器"和其它用户业务容器. 如果你使用过k8s的话,当然会了解pod的 ...

  2. APP自动化 -- 获取driver

    一.appium设置 1.打开appium 2.设置 appium服务器:点击  高级设置 3.启动 appium 服务器 二.查看  .apk  安装包的“包名”和“活动入口名” 1.先复制本地  ...

  3. MySQL主从分离实现

    前言   大型网站为了减轻服务器处理海量的并发访问,所产生的性能问题,采用了很多解决方案,其中最主流的解决方案就是读写分离,即将读操作和写操作分别导流到不同的服务器集群执行,到了数据业务层,数据访问层 ...

  4. hdu6755 Mow

    半平面交+数组模拟双端队列 人生第一次代码过两百行啊...加油加油 #include<iostream> #include<algorithm> #include<cma ...

  5. fgdsafhak

  6. matplotlib 显示中文问题

    import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签plt.rcParams[' ...

  7. PHP registerXPathNamespace() 函数

    实例 为下一个 XPath 查询创建命名空间上下文: <?php$xml=<<<XML高佣联盟 www.cgewang.com<book xmlns:chap=" ...

  8. IDEA、maven创建webapp项目

      maven官方入门指南:http://maven.apache.org/guides/getting-started/index.html 推荐跟着官方文档学习噢~   IDEA.maven创建w ...

  9. Vue Router详细教程

    1.什么是路由 1.1路由简介 说起路由你想起了什么?路由是一个网络工程里面的术语. 路由(routing)就是通过互联的网络把信息从源地址传输到目的地址的活动. --- 维基百科 额,啥玩意? 没听 ...

  10. Linux的VMWare中Centos7磁盘分区管理 fdisk分区和制作文件系统格式化和开机自动挂载

    一.硬盘的组成零件扇区 磁道 磁盘容量 磁盘分区 简介 硬盘由容量.柱面数.磁头数.扇区数 C/H/S, Cylinder, Head, Sector(柱面/磁头数/扇区数) 1.磁头数表示硬盘总共有 ...