题面

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. 代码Verify简介

    序 对于开发者而言,编译代码和提交代码是必不可少的流程,同一个需求反复提交的情况也时常出现,那么怎么避免这种情况,且保证代码的质量,这就是Verify CI的目标.Verify表示认证验证的意思,结合 ...

  2. 【最短路+bfs+缩点】Paint the Grid Reloaded ZOJ - 3781

    题目: Leo has a grid with N rows and M columns. All cells are painted with either black or white initi ...

  3. Java继承多态

    一. 父类引用指向子类对象父类名(接口名) 对象名=new 子类(接口)名称() 二. 父子继承关系中,成员变量重名1.直接通过子类对象访问成员变量 =左边是谁,就优先用谁2.间接通过成员方法访问成员 ...

  4. 附001.Nginx location语法规则

    一 location规则 1.1 location语法 基本语法: location [=|~|~*|^~]/uri/{...} 修饰符释义: 1 = #表示精确严格匹配,只有请求的url路径与后面的 ...

  5. Dcoker docker: Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).

    https://stackoverflow.com/questions/46533482/error-starting-userland-proxy-bind-for-0-0-0-080-unexpe ...

  6. java判断当前系统是win还是linux

    private static final boolean isWin = System.getProperty("os.name").toLowerCase().contains( ...

  7. 小白入门python新手教程python

    python教程很多,但是需要自学教程更好一些,看自学python教程3遍,然后一步步操作,7天后就会有很大的收货. 要向数据处理方向走,数据处理需要网络爬虫的知识,且更加精进.下面是我从网上查找这方 ...

  8. Csrf+Xss组合拳

    本文首发于“合天智汇”公众号,作者: 影子 各位大师傅,第一次在合天发文章,请多多关照 今年年初的疫情确实有点突然,打乱了上半年的所有计划(本来是校内大佬带我拿奖的时刻,没了 ,学长毕业了,就剩下我这 ...

  9. Mybatis-Plus中Wrapper的方法

    public interface EntityService extends IService<TbEntity>{ }entityService.update(entity,Condit ...

  10. Python for循环通过序列索引迭代

    Python for 循环通过序列索引迭代: 注:集合 和 字典 不可以通过索引进行获取元素,因为集合和字典都是无序的. 使用 len (参数) 方法可以获取到遍历对象的长度. 程序: strs = ...