D. Little Victor and Set
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties:

  • for all x  the following inequality holds l ≤ x ≤ r;
  • 1 ≤ |S| ≤ k;
  • lets denote the i-th element of the set S as si; value  must be as small as possible.

Help Victor find the described set.

Input

The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)).

Output

Print the minimum possible value of f(S). Then print the cardinality of set |S|. Then print the elements of the set in any order.

If there are multiple optimal sets, you can print any of them.

Examples
input
8 15 3
output
1
2
10 11
input
8 30 7
output
0
5
14 9 28 11 16
Note

Operation  represents the operation of bitwise exclusive OR. In other words, it is the XOR operation.

分析:

分类讨论:

No.1 r-l<=10

直接暴力搜索...

No.2 k=1

此时直接输出l...

No.3 k=2

ans一定是1...(相邻两个xor一下...)

No.4 k>=4

ans一定是0...(相邻4个xor一下...)

No.5 k=3

我们找出最小的m使得2^m大于l...

这样,如果存在三个数x=2^m-1,y=2^m+2^(m-1),z=2^m+2^(m-1)-1,那么就一定可以是0,否则若y>r,ans一定是1...

证明如下:

如果存在m+1能够满足解,那么m也一定可以找到合法解...

因为要使得ans=0,所以第m位一定存在两个1,因此m-1位一定存在1,所以最大值的下界是2^m+2^(m-1)-1,最小值的上界是2^m-1...

代码:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
#define int long long
using namespace std;
//眉眼如初,岁月如故 int l,r,k,ans,vis; inline void dfs(int x,int tmp,int lala,int cnt){
if(lala)
if(ans>=tmp)
ans=tmp,vis=lala;
if(x==r+1||cnt>k)
return;
dfs(x+1,tmp,lala,cnt);dfs(x+1,tmp^x,lala|(1<<x-l),cnt+1);
} signed main(void){
scanf("%I64d%I64d%I64d",&l,&r,&k);
if(r-l<=10){
ans=r;dfs(l,0,0,1);printf("%I64d\n",ans);ans=vis;int cnt=0;
while(ans)
cnt+=ans&1,ans>>=1;
printf("%I64d\n",cnt);cnt=0;
while(vis){
if(vis&1)
printf("%I64d ",l+cnt);
cnt++,vis>>=1;
}
puts("");
}
else if(k==1)
printf("%I64d\n1\n%I64d\n",l,l);
else if(k==2){
puts("1");puts("2");
if(l&1)
printf("%I64d %I64d",l+1,l+2);
else
printf("%I64d %I64d",l,l+1);
}
else if(k>=4){
puts("0");puts("4");
if(l&1){
for(int i=l+1;i<=l+4;i++)
printf("%I64d ",i);
puts("");
}
else{
for(int i=l;i<=l+3;i++)
printf("%I64d ",i);
puts("");
}
}
else{
int m,L=1,R=62;
while(L<=R){
int mid=(L+R)>>1;
if((1LL
<<mid)>l)
m=mid,R=mid-1;
else
L=mid+1;
}
if(m==0){
puts("1");puts("2");
if(l&1)
printf("%I64d %I64d",l+1,l+2);
else
printf("%I64d %I64d",l,l+1);
}
else{
if((1LL<<m)+(1LL<<m-1)>r){
puts("1");puts("2");
if(l&1)
printf("%I64d %I64d",l+1,l+2);
else
printf("%I64d %I64d",l,l+1);
}
else{
puts("0");puts("3");int x=(1LL<<m)-1,y=(1LL<<m)+(1LL<<m-1),z=(1LL<<m)+(1LL<<m-1)-1;
printf("%I64d %I64d %I64d\n",x,y,z);
}
}
}
return 0;
}//Cap ou pas cap. Pas cap.

  


By NeighThorn

Codeforces 460D. Little Victor and Set的更多相关文章

  1. Codeforces 460D Little Victor and Set(看题解)

    Little Victor and Set 其他都很好求, 只有k == 3的时候很难受.. 我们找到第一个不大于l的 t, 答案为 l, 3 * t, (3 * t) ^ l 感觉好像是对的, 感觉 ...

  2. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  3. codeforces 460D Little Victor and Set(构造、枚举)

    最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...

  4. codeforces 460D:Little Victor and Set

    Description Little Victor adores the sets theory. Let us remind you that a set is a group of numbers ...

  5. Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

    题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...

  6. Codeforces 460 D. Little Victor and Set

    暴力+构造 If r - l ≤ 4 we can all subsets of size not greater than k. Else, if k = 1, obviously that ans ...

  7. 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid

    题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...

  8. 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?

    题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

随机推荐

  1. 短短几行css代码实现滚动条效果

    如何实现使用css实现滚动条效果 实现效果,运用线性渐变来实现功能 假设我们的页面被包裹在 <body> 中,可以滚动的是整个 body,给它添加这样一个从左下到到右上角的线性渐变: bo ...

  2. git与github账号建立SSH连接

    第1步:创建SSH Key.在用户主目录下,(就是在你的工作空间一层)看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步 ...

  3. django-redis缓存记录

    对于站点缓存,我们使用redis这款key-value数据库.Redis有着更为复杂的数据结构并且提供对他们的原子性操作,这是一个不同于其他数据库的进化路径.Redis的数据类型都是基于基本数据结构的 ...

  4. nginx反向代理后端web服务器记录客户端ip地址

    nginx在做反向代理的时候,后端的nginx web服务器log中记录的地址都是反向代理服务器的地址,无法查看客户端访问的真实ip. 在反向代理服务器的nginx.conf配置文件中进行配置. lo ...

  5. windows 时间同步至最新时间方法 | windows 时间同步服务器

    国内 windows 系统的电脑有时候不能自动同步互联网当前时间,这就需要改一下 windows 的时间同步服务器 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址:https://ww ...

  6. JavaScript常用八种继承方案

    更新:在常用七种继承方案的基础之上增加了ES6的类继承,所以现在变成八种啦,欢迎加高级前端进阶群一起学习(文末). --- 2018.10.30 1.原型链继承 构造函数.原型和实例之间的关系:每个构 ...

  7. MTCNN学习资源

    MTCNN pytorch版本的实现 TropComplique/mtcnn-pytorch https://github.com/TropComplique/mtcnn-pytorch MTCNN实 ...

  8. GoF23种设计模式之结构型模式之桥接模式

    一.概述         将类的抽象部分与实现分部分离开来,使它们都可以独立地变化. 二.适用性 1.你不希望在抽象和实现之间有一个固定的绑定关系的时候.例如:在程序运行时实现部分应可以被选择或切换. ...

  9. POJ 2763 Housewife Wind 树链拋分

    一.前言 这破题WA了一天,最后重构还是WA,最后通过POJ讨论版得到的数据显示,我看上去是把某个变量写错了..于是,还是低级错误背锅啊....代码能力有待进一步提升2333333 二.题意 某家庭主 ...

  10. C++ 11 从C++ primer第五版的学习笔记

    1. auto (page107) auto 推断会忽略const   const int ci = i, & cr = ci; auto b = ci; // b is an int (to ...