CF 262Div2 D Little Victor and Set
来源:互联网 发布:公司邮箱的域名是什么 编辑:程序博客网 时间:2024/05/22 09:18
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.
The first line contains three space-separated integers l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)).
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.
8 15 3
1210 11
8 30 7
0514 9 28 11 16
1. k=1,则答案为l
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;}
- CF 262Div2 D Little Victor and Set
- Codeforces Round #262 (Div. 2) D Little Victor and Set
- Codeforces 460 D. Little Victor and Set
- Codeforces 460D Little Victor and Set(构造)
- codeforces #460D Little Victor and Set 构造
- codeforces 460D Little Victor and Set(构造)
- [Codeforces 460D] Little Victor and Set (构造)
- codeforces 460D Little Victor and Set(构造)
- CF #136Div2 D. Little Elephant and Array
- [Codeforces460D] Little Victor and Set(构造)
- 【瞎搞】 Codeforces 460D Little Victor and Set 位运算构造
- Codeforces 460d Littel victor and set
- 【Codeforces Round 262 (Div 2)D】【构造】Little Victor and Set 集合最多取k数使得异或值尽可能小
- CF#310 div2 D set+pair+贪心
- CF(#294 div2):D. A and B and Interesting Substrings
- Codeforces #669 Div2. D. Little Artem and Dance(思维)
- CF 174(div2) D
- CF 161 div2 D
- linux关闭防火墙
- 公司和员工发展
- 安卓纯java写Spinner
- 辽宁经济“自由落体”式下滑:民众捂紧口袋喊穷
- AppWidget详解
- CF 262Div2 D Little Victor and Set
- Ambari系列(三): Ambari架构详解
- 【BZOJ 1046】 [HAOI2007]上升序列
- JDK6和JDK7中String 类的substring方法
- java中JVM的原理
- Web Api 测试
- median of two sorted arrays
- 友情链接
- CentOS6.5安装Chromium谷歌浏览器