CodeForces 1174D Ehab and the Expected XOR Problem
题意:
给定两个数\(n\)和\(x\),构造一个序列,设为\(a[l]\)(\(l\)不确定)
\(1\)、\(1\leq a[i]<2^{n}\)
\(2\)、序列中没有子序列异或和为\(0\)或\(x\)
\(3\)、\(l\)应最长
分析:
\(1\)、设前\(i\)个数字异或和为\(sum_{i}\),则对于\([i,j]\)的异或和为\(sum_{i}⨁sum_{j-1}\),所以我们可以找出\(sum\)数组,满足
\]
\(2\)、异或性质有\(y⨁z=x\),则有\(y⨁x=z\),且对于任意一个数\(y\),\(z\)是惟一的。且由于\(y\)和\(z\)在二进制下是不可能超过\(2^{n}\)的,因此,相对立的\(y\)和\(z\)在\(2^{n}\)内成对存在,设\(i\)从\(1\)开始遍历到\(2^{n}\),我们与将\(i\)对立的数标记即可,我们可以得到\(sum\)数组
\(3\)、\(a[i]=sum[i]⨁sum[i-1]\),输出数组即可
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
using namespace std;
const int maxn = (ll) 5e5 + 5;
const int mod = 1000000007;
const int mod2 = 1000000006;
const int inf = (ll) 1e9 + 5;
bool vis[maxn];
signed main() {
start;
int n, x;
cin >> n >> x;
vis[x] = vis[0] = true;
vector<int> ans;
ans.push_back(0);
for (int i = (1 << n) - 1; i > 0; --i)
if (!vis[i]) {
ans.push_back(i);
vis[i ^ x] = true;
}
cout << ans.size() - 1 << '\n';
for (int i = 1; i < ans.size(); ++i)
cout << (ans[i - 1] ^ ans[i]) << ' ';
return 0;
}
CodeForces 1174D Ehab and the Expected XOR Problem的更多相关文章
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- Codeforces.1088D.Ehab and another another xor problem(交互 思路)
题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...
- 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 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 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- 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/ ...
随机推荐
- 2023-05-24:为什么要使用Redis做缓存?
2023-05-24:为什么要使用Redis做缓存? 答案2023-05-24: 缓存的好处 买啤酒和喝啤酒的例子可以帮助我们理解缓存的好处. 假设你在超市里买了一箱啤酒,如果你需要每次想喝啤酒就去超 ...
- 生信服务器 | Linux 时间戳和标准时间
在 Linux 系统中,有许多场合都使用时间戳的方式表示时间,即从1970年1月1日起至当前的天数或秒数.如/etc/shadow里的密码更改日期和失效日期,还有代理服务器的访问日志对访问时间的记录等 ...
- 安装指定版本的mysql(mysql5.7)
安装指定版本的mysql(mysql5.7) 目标:解决需求,安装mysql5.7 前言: 安装软件的三种方式: rpm 安装 源代码编译安装 yum仓库安装 本地光盘 阿里云yum源 自建yum仓库 ...
- RedHat7.4配置yum源(原创!详细易懂)
redhat7 .4配置centOS yum源(自带yum文件) 1.定位到yum的配置文件 root@192.168.6.129:/etc# cd yum.repos.d 2.检查yum是否安装,以 ...
- Helm实战案例一:在Kubernetes上使用Helm搭建Prometheus Operator监控
目录 一.系统环境 二.前言 三.Prometheus Operator简介 四.helm安装prometheus-operator 五.配置prometheus-operator 5.1 修改gra ...
- 了解基于模型的元学习:Learning to Learn优化策略和Meta-Learner LSTM
摘要:本文主要为大家讲解基于模型的元学习中的Learning to Learn优化策略和Meta-Learner LSTM. 本文分享自华为云社区<深度学习应用篇-元学习[16]:基于模型的元学 ...
- in用不用索引,啥时候能用啥时候不能用,一文说清
in/or到底能不能用索引应该是肯定的,但有时生效有时不生效,这个能不能量化计算?这是本文想讨论和解答的问题. in到底用不用索引感觉像一桩悬疑片!古早时期的面经,统一说不走索引,在一些程序员脑海中从 ...
- Blazor前后端框架Known-V1.2.1
V1.2.1 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. 概述 基于C#和Blazor实现的快速开发框架,前后端分离,开箱即用. 跨平台,单 ...
- ASL单芯片CS5366TypeC转HDMI4K60HZ加HUB多口方案|CS5366带PD拓展方案原理图
CS5366芯片是ASL集睿致远最新推出的2Len带PD的扩展坞方案芯片,CS5366支持4K60HZ. 在分辨率4K下,刷新率60HZ对于30HZ看似提升不多,但是对于应用在游戏主座的客户来说至关重 ...
- 【调制解调】VSB 残留边带调幅
说明 学习数字信号处理算法时整理的学习笔记.同系列文章目录可见 <DSP 学习之路>目录,代码已上传到 Github - ModulationAndDemodulation.本篇介绍 VS ...