CF 262Div2 D Little Victor and Set

来源:互联网 发布:公司邮箱的域名是什么 编辑:程序博客网 时间:2024/05/22 09:18

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.

Sample test(s)
input
8 15 3
output
1210 11
input
8 30 7
output
0514 9 28 11 16
解析

1. k=1,则答案为l

2. k=2,如果可以选择一奇一偶,这里偶数比奇数小1,则答案为0,否则选择l和l^r中较小的一个
3. k=4,如果可以选择四个连续的数,使得最小的一个数为偶数,则答案为0,否则转k=3或k=2或k=1处理
4. k=3,找出形如 11xxxx,10zzzz,01yyyy,这里10zzzz=11xxxx^01yyyy,基于贪心的思想可以将01yyyy取为l(?),算出11xxxx<=r,则答案为0,否则转k=2或k=1处理
转载http://blog.csdn.net/cq_phqg/article/details/38796199

k=3的情况讲得不是很清楚:我们要尽可能地凑出答案为0的情况。那么如下,当每一列的1成对存在时,答案就是0,。

1010100001
0010101001
1001001000

假设有这样三个数:

a:11xxxxxxx
b:10yyyyyyy
c:01zzzzzzz

它们必然满足a>b>c,为了使a和c尽量落在[l,r]之间,则c尽量地大,取011111111,a尽量地小,取110000000。所以只要110000000<r,答案就是0。

顺便说一句,c可以取[l,011111111]之间的任意数,因为我始终可以通过调整b的值(确切地讲就是c有0的地方b也是0,c有1的地方b也是1)来保障a取110000000。

注意:位运算的优先级比&& || < <= == > >=等低。

#include<cstdio>using namespace std;typedef long long LL;LL l,r,k;void work(){if(k>=4 && !(l&1)) {printf("0\n4\n%I64d %I64d %I64d %I64d",l,l+1,l+2,l+3);return;}if(k>=4 && (l&1) && (l+4<=r)){printf("0\n4\n%I64d %I64d %I64d %I64d",l+1,l+2,l+3,l+4);return;}if(k>=3) {LL i=1;for(;i<=l;i=i<<1);if(r>=i+(i>>1)) {printf("0\n3\n%I64d %I64d %I64d",l,l^(i+(i>>1)),i+(i>>1));return;}}if(k>=2){if(l+1==r && (l&1))//odd+evenif((l^r)>=l) {printf("%I64d\n1\n%I64d",l,l); return;}//lelse {printf("%I64d\n2\n%I64d %I64d",l^r,l,r); return;}//l^rprintf("1\n2\n");if(l&1)//l is oddprintf("%I64d %I64d",l+1,l+2);//1else printf("%I64d %I64d",l,l+1);//1return;}if(k>=1) {printf("%I64d\n1\n%I64d",l,l); return;}//l}int main(){while(scanf("%I64d%I64d%I64d",&l,&r,&k)==3){work();printf("\n");}return 0;}


0 0