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 ]表示对于 ...
随机推荐
- git忽略而不提交文件的3种情形
1.从未提交过的文件可以用.gitignore 也就是添加之后从来没有提交(commit)过的文件,可以使用.gitignore忽略该文件 该文件只能作用于未跟踪的文件(Untracked Files ...
- 给枚举定义DescriptionAttribute
在C#中,枚举用来定状态值很方便,例如我定义一个叫做Season的枚举 public enum Season { Spring = 1, Summer = 2, Autumn = 3, Winter ...
- 使用.Net Core 2.2创建windows服务
使用.Net Core 2.2创建windows服务 我的环境 win 10 home Visual Studio 2019 v16.1.3 安装有.net core 2.2 创建项目 编辑项目文件 ...
- 关于Mybatis的几件小事(二)
一.MyBatis缓存机制 1.简介 Mybatis包含了一个非常强大的查询缓存的特性,它可以非常方便地配置和定制. 缓存key极大提高查询效率 MyBatis系统中默认定义了两次缓存 默认情况下,只 ...
- 微信小程序登录获取手机号
一,发送请求携带 code 到后台换取 openid var that = this; wx.login({ success(res) { console.log(res); var code = r ...
- 逗渣的学习笔记-关于webpack从头撸一遍
刚开始接触webpack,完全是工作需求.那是去年年末的事情了,当时被迫换到另一个项目组,也是一个新的项目,做手机上面的应用,客户要求用react做应用,所以完全属于赶鸭子上架,当时说真的蛮懵逼的,也 ...
- C和指针--编程题9.14第10小题--判断回文函数
题目: 编写函数 int palindrom( char *string); 如果参数字符串是个回文,函数就返回真,否则就返回假.回文就是指一个字符串从左向右读和从右向左读是一样的.函数应忽略所有的非 ...
- Ubuntu安装Python 3.6之编译安装+使用PPA源安装
下面分别详细介绍一下Ubuntu 14.04/16.04安装Python 3.6的两种方法: 方法一 自己编译安装: # 安装编译必需的软件包 sudo apt install build-essen ...
- Hadoop_28_MapReduce_自定义 inputFormat
1. 自定义inputFormat 1.1.需求: 无论hdfs还是mapreduce,对于小文件都有损效率,实践中,又难免面临处理大量小文件,此时就需要有相应解决方案; 1.2.分析: 小文件的优化 ...
- java——java跨平台原理
不同操作系统不同的虚拟机,屏蔽不同系统指令集的差异. 开发程序只需要遵循java规范: