CF1174D Ehab and the Expected XOR Problem
思路:
使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x。
实现:
#include <bits/stdc++.h>
using namespace std;
int vis[ << ];
int main()
{
int n, x;
while (cin >> n >> x)
{
memset(vis, , sizeof vis);
vector<int> v;
if (x >= ( << n))
{
for (int i = ; i < ( << n); i++) v.push_back(i);
}
else
{
for (int i = ; i < ( << n); i++)
{
if (i == x) continue;
else if (!vis[i]) { v.push_back(i); vis[i ^ x] = ; }
}
}
cout << v.size() << endl;
if (!v.empty())
{
cout << v[] << " ";
for (int i = ; i < (int)v.size(); i++) cout << (v[i - ] ^ v[i]) << " ";
cout << endl;
}
}
return ;
}
CF1174D Ehab and the Expected XOR Problem的更多相关文章
- CF1174D Ehab and the Expected XOR Problem(二进制)
做法 求出答案序列的异或前缀和\(sum_i\),\([l,r]\)子段异或和可表示为\(sum_r\bigoplus sum_{l-1}\) 故转换问题为,填\(sum\)数组,数组内的元素不为\( ...
- 【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#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 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 ...
- 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的 ...
- 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/ ...
- Codeforces.1088D.Ehab and another another xor problem(交互 思路)
题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...
随机推荐
- zabbix的配置
一.网络自动发现: 1.zabbix的网络自动发现是一个非常强大的功能,该功能可以完成以下工作. a.快速发现并添加主机. b.简单的管理. c.随着环境的改变而快速搭建监控系统. 2.网络发现基于以 ...
- [poj3264]rmq算法学习(ST表)
解题关键:rmq模板题,可以用st表,亦可用线段树等数据结构 log10和log2都可,这里用到了对数的换底公式 类似于区间dp,用到了倍增的思想 $F[i][j] = \min (F[i][j - ...
- Maven Cargo 远程部署到tomcat7x
pom.xml中加入cargo的Plugin声明: <plugin> <groupId>org.codehaus.cargo</groupId> <artif ...
- Webservice 或者HttpRequest请求的时候提示 “指定的注册表项不存在”错误 解决方案
今天又遇到神奇的事情,在使用WebService的时候居然提示“指定的注册表不存在.” The specified registry key does not exist. Google后发现,原来是 ...
- Webpack 4教程 - 第八部分 使用prefetch和preload进行动态加载
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://wanago.io/2018/08/13/webpack-4-course-part ...
- CodeForces 114B 【STL应用】
思路: 原来string类能sort 和 swap....太强了.... 注意:字典序最小输出,因为某个地方写挫了,sort了n发,代码挫. #include <bits/stdc++.h> ...
- Unity 着色器训练营(2) - MVP转换和法线贴图
https://mp.weixin.qq.com/s/Qf4qT15s9bWjbVGh7H32lw 我们刚刚公布了Unity 2018.1中,Unity将会内置可视化编程工具Shader Graph, ...
- ES 6.1.2集群安装
1.下载java,并设置环境变量 sudo tar -zxvf jdk-8u191-linux-x64.tar.gz -C /usr/local/ sudo vim /etc/profile 在最后添 ...
- 洛谷P1275 魔板
P1275 魔板 题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状 ...
- CTS/APIO2019游记
退役后游记... 这次是真·游记了 ghj1222自从省选翻车后心情一直不错 5.12 (CTS 报到) 没去thupc(话说都不知道thupc这时候举行),于是就这天从衡水出发了 翻来覆去睡不着觉, ...