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. java面向对象思想1

    1.面向对象是面向过程而言.两者都是一种思想.面向过程:强调的是功能行为.(强调过程.动作)面向对象:将功能封装进对象,强调了具备了功能的对象.(强调对象.事物)面向对象是基于面向过程的.将复杂的事情 ...

  2. Oracle数据库学习(四)

    11.创建表 crate table tab1(f_id number not null,f_a varchar2(7) not null,f_b number(6,2) not null): 主键: ...

  3. vue学习之路 - 4.基本操作(下)

    vue学习之路 - 4.基本操作(下) 简述:本章节主要介绍 vue 的一些其他常用指令. Vue 指令 这里将 vue 的指令分为系统内部指令(vue 自带指令)和用户自定义指令两种. 系统内部指令 ...

  4. Java - 类加载的时候,是有缺省同步锁的

    类加载的时候,是有缺省同步锁的

  5. CentOS Linux 安装IPSec+L2TP

    第二层隧道协议L2TP(Layer 2 Tunneling Protocol)是一种工业标准的Internet隧道协议,它使用UDP的1701端口进行通信.L2TP本身并没有任何加密,但是我们可以使用 ...

  6. 自动发现项目中的URL,django1版本和django2版本

    一.django 1 版本 routers.py import re from collections import OrderedDict from django.conf import setti ...

  7. Linux命令之---touch

    命令简介 linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 命令格式 touch [选项]... 文件... 命令参数 -a   或 ...

  8. 笔记-python-selenium,phantomjs

    笔记-python-selenium,phantomjs 1.      简介 1.1.    selenium selenium是一款自动化测试工具,支持多种语言 为什么爬虫要使用selenium呢 ...

  9. 13,scrapy框架的日志等级和请求传参

    今日概要 日志等级 请求传参 如何提高scrapy的爬取效率 一.Scrapy的日志等级 - 在使用scrapy crawl spiderFileName运行程序时,在终端里打印输出的就是scrapy ...

  10. kettle Spoon.bat闪退解决办法!

    1.Java环境配置问题: java_home:D:\Program Files\Java\jdk1.7.0_25(安装jdk路径) classpath:.;%java_home%\lib\dt.ja ...