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 ]表示对于 ...
随机推荐
- java对象序列化并存储到文件中
● 如何将一个Java对象序列化到文件里 使用输入输出流,,一个是ObjectOutputStream 对象,ObjectOutputStream 负责向指定的流中写入序列化的对象.当从文件中读取序列 ...
- 故事板(StoryBoards)和动画(Animations)
Silverlight & Blend动画设计系列五:故事板(StoryBoards)和动画(Animations) 正如你所看到的,Blend是一个非常强大的节约时间的设计工具,在Blend ...
- django inclusion用法
概述: inclusion主要的是生成html标签, 返回的是一个字典,大分部跟simple_tag类似, simple_tag可返回任意类型的值 定义inclusion from django im ...
- go module 设置
国内无法获取被墙的go module,解决方法,设置环境变量 GO111MODULE=on goproxy=https://goproxy.io
- element ui的照片墙 默认显示照片
参考地址: element ui的照片墙 默认显示照片 照片显示的数据格式是:[{name: '', url: ''}],:file-list=""默认显示的图片 实际项目开发中需 ...
- UART串口简介
通用异步收发传输器(Universal Asynchronous Receiver Transmitter) 原理 发送数据时,CPU将并行数据写入UART,UART按照一定的格式在一根电线上串行发出 ...
- Java基础加强-内部类及代理
/*内部类是一个编译时的概念,*/ 常规内部类.静态内部类.局部内部类.匿名内部类 1.常规内部类(常规内部类没有static修饰且定义在外部类类体中) 1.常规内部类中的方法可以直接使用外部类的实例 ...
- 如何入门Pytorch之一:Pytorch基本知识介绍
前言 PyTorch和Tensorflow是目前最为火热的两大深度学习框架,Tensorflow主要用户群在于工业界,而PyTorch主要用户分布在学术界.目前视觉三大顶会的论文大多都是基于PyTor ...
- python遍历目录下所有文件
# -*- coding:utf-8 -*- import os if __name__ == "__main__": rootdir = '.\data' list = os.l ...
- java--springmvc
springmvc请求图 SpringMVC内部的执行流程1.用户发起到达中央调度器DispatcherServlet2.中央调度器DispatcherServlet把请求(some.do)交给了处理 ...