CF 262Div2 D Little Victor and Set

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
1
2
10 11
input
8 30 7
output
0
5
14 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+even
			if((l^r)>=l) {printf("%I64d\n1\n%I64d",l,l); return;}//l
			else {printf("%I64d\n2\n%I64d %I64d",l^r,l,r); return;}//l^r
		
		printf("1\n2\n");
		if(l&1)//l is odd
			printf("%I64d %I64d",l+1,l+2);//1
		else printf("%I64d %I64d",l,l+1);//1
		return;
	}
	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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值