CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m.
如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等.
而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m.
即 $xor[i]$^$xor[j]!=m$, $\Rightarrow$ m^xor[j] 这个异或前缀就不可以再次出现了.
用一个数组标记一下就好了~
#include <bits/stdc++.h>
#define N 1000000
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int vis[N],b[N];
void solve()
{
int n,m,i,j,cur=1,cnt=0;
memset(vis,0,sizeof(vis));
scanf("%d%d",&n,&m);
vis[m]=1;
for(i=1;i<=(1<<n);++i)
{
while(vis[cur]) ++cur;
if((cur^b[cnt-1]) >= (1<<n)) break;
b[++cnt]=cur;
vis[cur^m]=1;
++cur;
}
printf("%d\n",cnt);
for(i=0;i<cnt;++i) printf("%d ",b[i]^b[i+1]);
}
int main()
{
int i,j,T;
// setIO("input");
solve();
return 0;
}
CF D. Ehab and the Expected XOR Problem 贪心+位运算的更多相关文章
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- 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
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于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 ...
- 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\ ...
随机推荐
- glib系列2 APP编译
编译命令 gcc main.c `pkg-config --cflags glib-2.0 --libs glib-2.0` 头文件 $ ls /usr/local/include/glib-2.0/ ...
- 谈谈Python中pop与remove的用法
remove() 函数用于移除列表中某个值的第一个匹配项. remove()方法语法: list.remove(obj) 如果obj不在列表中会引发 ValueError 错误,通常先使用count ...
- 使用DANT做FTP的转发代理
FTP不能直接使用nginx进行转发,想了一些办法,最后决定使用iptalbes做DNAT,相关于把这个机器做一台防火墙,做一个NAT 1.启用ip_forward vim /etc/sysctl.c ...
- 关于OI中的各种数学
学到后面数学越来越多了,感觉好难啊,开个博客专门记录一下数学相关的东西 因为反正也没人看,所以主要还是给自己看的 一些符号: 数论函数的卷积:$\ast$,$ h = f \ast g$ 则 $h(n ...
- Unity UGUI动态生成控件
一. 首先你得先清楚RectTransform组件的一些程序控制 1. 先得到UGUI控件上面的RectTransform组件 RectTransform rtr = gameObject.GetCo ...
- Java HeapSort
Java HeapSort /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternational & ...
- eclipse复制工作空间配置步骤
多个workspace,把每个workspace的设置共享,省去每次都重新配置一次. 总结一下,复制工作空间配置步骤如下: [最好是在新的workspace创建项目之前操作] 1 使用eclipse新 ...
- cmd查找端口占用情况
查找端口占用情况:netstat -ano|findstr 4848 查看使用指定端口的应用程序:tasklist|findstr xxxx,xxxx指的是pid 结束指定进程:taskkill /p ...
- Python练习_函数进阶_day10
1. 1.作业 1,写函数,接收n个数字,求这些参数数字的和.(动态传参) 2,读代码,回答:代码中,打印出来的值a,b,c分别是什么?为什么? a=10 b=20 def test5(a,b): p ...
- FPGA上外挂DDR2&DDR3&MIG IP的使用记录
前言 当需要大容量数据存储及处理的时候,FPGA内部自带的存储资源是远远不够的,所以问题来了,怎么使用外带的DDR3? 首要问题在于DDR3是什么?有没有协议?当然只是需要用Xilinx MIG IP ...