codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接:
http://codeforces.com/contest/1174/problem/D
题意:
构造一个序列,满足以下条件
- 他的所有子段的异或值不等于$x$
- $1 \le a_i<2^n$
输出一个最长的这样的序列
数据范围:
$1 \le n \le 18$
$1 \le x<2^{18}$
分析:
比赛的时候搞混$subsegment$和$subsequence$,前者为子段一定要连续,后者为子序列可以不连续
赛后看的官方题解
假设构造的序列为$a_i$,它的前缀异或和为$b_i$
即:$b_i=a_1\bigoplus a_2 \bigoplus a_3\bigoplus a_4.....\bigoplus a_i$
$b_i$必须满足以下条件
- 没有重复的元素即$b_i\neq b_j$
- 没有一对元素的异或值为$x$
- 里面没有$x$
关于第二条,我们可以知道,如果$g$加入在$b$数组中,那么$g\bigoplus x$不在$b$数组中,所以这两个数选其中之一就行
得到b数组之后$a_i=b_i \oplus b_{i-1}$
ac代码:
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const ll mod=998244353;
int ans[maxn];
inline ll cal(int st,int len)
{
return (ll)len*(2*st+len-1)/2;
}
int main()
{
int n,k;
while(scanf("%d %d",&n,&k)==2)
{
if(cal(1,k)>n)
{
printf("NO\n");
continue;
}
if(n==4&&k==2)
{
printf("NO\n");
continue;
}
else if(n==8&&k==3)
{
printf("NO\n");
continue;
}
int st=1,en=n;
while(st!=en)
{
int md=(st+en)/2;
if(cal(md+1,k)<=n)st=md+1;
else en=md;
}
for(int i=1;i<=k;i++)
ans[i]=st+i-1;
int now=n-cal(st,k),inde=k;
while(now)
{
if(ans[inde]+1<=2*ans[inde-1])ans[inde]++,inde--,now--;
else inde=k;
}
printf("YES\n");
for(int i=1;i<=k;i++)
{
printf("%d",ans[i]);
if(i==k)printf("\n");
else printf(" ");
}
}
return 0;
}
codeforces#1157D. 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: · ...
- 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 D - Ehab and another another xor problem /// 构造
题目大意: 本题有两个隐藏起来的a b(1<=a,b<=1e30) 每次可 printf("? %d %d\n",c,d); 表示询问 a^c 与 b^d 的相对大小 ...
- 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 #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 ]表示对于 ...
随机推荐
- Callable和Future的区别
Callable 在Java中,创建线程一般有两种方式,一种是继承Thread类,一种是实现Runnable接口.然而,这两种方式的缺点是在线程任务执行结束后,无法获取执行结果.我们一般只能采用共享变 ...
- MQTT协议探究(一)
1 准备阶段 MQTT客户端:https://www.cnblogs.com/linzhanfly/p/9923577.html WireShark MQTT服务器(iot.eclipse.org) ...
- 【原创】大叔经验分享(79)mysql内存设置
mysql内存设置,首先要知道当前的设置 MySQL [(none)]> show variables like '%buffer%'; +--------------------------- ...
- 07 Redis存储Session
django-redis-sessions 官方文档:https://pypi.org/project/django-redis-sessions/ dango-redis 官方文档:http://n ...
- fragment概念理解
fragment概念理解知识,fragment概念理解图片 fragment概念理解内容,fragment概念理介绍,fragment概念理正文 Fragment是Android honeycomb ...
- JS 发送弹幕
JS实现弹幕的发送 <div class="box1"> <div class="box2" style="width: 600px ...
- TP5 用cron实现linux定时任务
TP5 用cron实现linux定时任务 1) tp5的控制器内容: namespace app\test\controller; use think\Controller; use think\fa ...
- Linux--查询文件的第几行到第几行命令
cat catalina.out | tail -n +14000 | head -n 10000 | sort | uniq -c linux 如何显示一个文件的某几行(中间几行)[一]从第3000 ...
- 大幅提升Delphi Datasnap数据传输效率的方法
方法一:增加TCP读写缓存的大小 DataSnap Server中负责TCP/IP通讯的组件是TDSTCPServerTransport,它默认的TCP/IP读写缓冲区的大小为32KB,由 ...
- C#中使用ListView动态添加数据不闪烁(网上方法会出问题)
最近需要使用做一个动态行显示,所以就用到了ListView控件,在网上也查到了关于动态添加不闪烁的方式都是如下: 首先,自定义一个类ListViewNF,继承自 System.Windows.Form ...