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. STL笔记(こ)--删除数组中重复元素

    使用STL中的Unique函数: #include<bits/stdc++.h> using namespace std; void fun(int &n) //配套for_eac ...

  2. nginx平滑升级的过程

    1.开始之前首先查看当前的使用版本以及编译时的参数: [root@www ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.2 ...

  3. jQuery具体实例介绍什么时候用ajax,ajax应该在什么地方使用

    网站开发时,ajax是一个非常方便的工具,它具有和表单相同的功能完成前端和后台之间的交互!它起到局部刷新的功能!那什么时候用ajax呢?下面给大家介绍几个实例,首先应该分为两类:  一.在用表单和aj ...

  4. 第37课 thinkphp5添加商品基本信息及通过前置钩子上传商品主图 模型事件(勾子函数)

    目录 手册地址: before_insert(新增之前的操作) 要实现的功能 思路 触发条件: 1. 控制器里必须要调用模型的save()方式保存数据,用insert()触发不了勾子函数的 2. 模型 ...

  5. java+Mysql大数据的一些优化技巧

    众所周知,java在处理数据量比较大的时候,加载到内存必然会导致内存溢出,而在一些数据处理中我们不得不去处理海量数据,在做数据处理中,我们常见的手段是分解,压缩,并行,临时文件等方法; 例如,我们要将 ...

  6. Python基础函数必学

    我们知道圆的面积计算公式为: S = πr2 当我们知道半径r的值时,就可以根据公式计算出面积.假设我们需要计算3个不同大小的圆的面积: r1 = 12.34 r2 = 9.08 r3 = 73.1 ...

  7. A1027 Colors in Mars (20)(20 分)

    A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...

  8. 水题:HDU1303-Doubles

    Doubles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  9. 华东交通大学2018年ACM“双基”程序设计竞赛 D

      摸鱼之王MIKU酱想去埃及玩,需要一个人陪同.小新和小磊都想陪MIKU酱一起去,但名额只有一个.所以小磊和小新决定用一个小游戏来决定谁和MIKU酱出去玩.    游戏的道具是21张塔罗牌,塔罗牌分 ...

  10. PAT乙级1088

    1088 三人行 (20 分) 子曰:“三人行,必有我师焉.择其善者而从之,其不善者而改之.” 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整数:把甲的能力值的 2 个数字调换位 ...