【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面
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 - 构造的更多相关文章
- CF1174D Ehab and the Expected XOR Problem
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...
- CF1174D Ehab and the Expected XOR Problem(二进制)
做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 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的 ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- 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 的相对大小 ...
- 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 ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- 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/ ...
随机推荐
- JAVA基础系列:JDK目录结构
0. 名词解释 SDK: Softeare Development Kit,用于开发JavaEE,包括JDK. JDK: Java Development Kit,java开发工具包,包括Java编译 ...
- 深入探究JVM之内存结构及字符串常量池
前言 Java作为一种平台无关性的语言,其主要依靠于Java虚拟机--JVM,我们写好的代码会被编译成class文件,再由JVM进行加载.解析.执行,而JVM有统一的规范,所以我们不需要像C++那样需 ...
- vue学习(四) v-on:事件绑定
//html <div id="app"> <input type="button" value="ok" v-bind: ...
- Redis网络模型的源码分析
Redis的网络模型是基于I/O多路复用程序来实现的.源码中包含四种多路复用函数库epoll.select.evport.kqueue.在程序编译时会根据系统自动选择这四种库其中之一.下面以epoll ...
- Python之数据结构:列表、元组、字典、set
列表 列表里可以存储任意的数据类型.可修改的结构,用[ ]括起来表示或用函数list()构建. eg: y = [1,1.5,'hello',True] 列表还可以嵌套列表 eg: y = [1,1. ...
- Redis一站式管理平台工具,支持集群创建,管理,监控,报警
简介 Redis Manager 是 Redis 一站式管理平台,支持集群的创建.管理.监控和报警. 集群创建:包含了三种方式 Docker.Machine.Humpback: 集群管理:支持节点扩容 ...
- Spring报错: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [xxx]
如果确实没有这个类,就挨个将总项目,子项目clean,install一下,注意他们的依赖关系.
- Django学习路17_聚合函数(Avg平均值,Count数量,Max最大,Min最小,Sum求和)基本使用
使用方法: 类名.objects.aggregate(聚合函数名('表的列名')) 聚合函数名: Avg 平均值 Count数量 Max 最大 Min 最小 Sum 求和 示例: Student.ob ...
- PHP ftp_systype() 函数
定义和用法 ftp_systype() 函数返回 FTP 服务器的系统类型标识符. 如果成功,该函数返回系统类型.如果失败,则返回 FALSE. 语法 ftp_systype(ftp_connecti ...
- PHP sscanf() 函数
实例 Parse a string: <?php高佣联盟 www.cgewang.com$str = "age:30 weight:60kg";sscanf($str,&qu ...