Codeforces Round #262 (Div. 2) 1004

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



10 11

input

8 30 7

output



14 9 28 11 16

Note

Operation

represents the operation of bitwise exclusive OR. In other words, it is the XOR operation.

【分析】很显然的结论,K^(K+1)=1,其中K是偶数。当K>3时,我们可以选连续的4个自然数使异或和为0。(当然注意要特判R-L+1的大小)。当K=1时,就是L。当K=2时,显然只能构造异或为1的情况。

所有的推论都指向一个问题:当K=3的一般情况怎么做?

【题解】对于那个情况,我一直觉得能贪心构造,但是怎么也想不出简单易行且效率高的算法。

其实很简单。我们设L<=X<Y<Z<=R,然后来贪心构造他们。

在二进制中,异或和为0的情况是1,1,0或0,0,0。显然Z的第一位是1,然后X和Y是0。

因为是贪心,我们要尽量使Y靠近Z(因为如果Z符合范围,Y显然越大越好)。

那么第二位我们就让Y靠近Z。我们把Z那位设成0,X和Y都设成1,即如下形式:

110000000

101111111

011111111

wa了很多次,

1.没有用long long

2.只有l^(l+1) l为偶数时,才能异或值为1

3.当k>=4但是不存在4个数异或为0的时候,没考虑3个也可能为0

4.1<<35超过int 得写成(long long)1<<35

5.当2个异或不是1时,应该判断他的值和l的大小

 #include <cstring>

 #include <iostream>

 #include <algorithm>

 #include <cstdio>

 #include <cmath>

 #include <map>

 #include <cstdlib>

 #define M(a,b) memset(a,b,sizeof(a))

 #define INF 0x3f3f3f3f

 using namespace std;

 long long l,r,k;

 int main()

 {

     scanf("%I64d%I64d%I64d",&l,&r,&k);

     if(k==) printf("%I64d\n1\n%I64d\n",l,l);

     else if(k==)

     {

         if(l%==)

         printf("1\n2\n%I64d %I64d\n",l,l+);

         else if(l+<=r)

         printf("1\n2\n%I64d %I64d\n",l+,l+);

         else if(((l)^(l+))<l) {

                 //cout<<(((l)^(l+1))-l)<<endl;

                 printf("%I64d\n2\n%I64d %I64d\n",(l)^(l+),l,l+);

         }

         else printf("%I64d\n1\n%I64d\n",l,l);

     }

     else if(k>=)

     {

         if(l%==)

           printf("0\n4\n%I64d %I64d %I64d %I64d\n",l,l+,l+,l+);

         else if(l+<r)

           printf("0\n4\n%I64d %I64d %I64d %I64d\n",l+,l+,l+,l+);

         else if(((l)^(l+)^(l+)^(l+))==)printf("0\n4\n%I64d %I64d %I64d %I64d\n",l,l+,l+,l+);

          else

     {

         int count1 = ;

         long long tem1 = r;

         while(tem1>)

         {

             tem1 = tem1>>;

             count1++;

         }

         //cout<<count1<<endl;

         int cnt = ;

         long long ans1 = ;

         long long ans2 = ;

         for(int i = count1-;i>=;i--)

         {

             if(((r>>i)&)==)

             {

                 if(cnt == )

                 {

                   ans1 = ans1|((long long)<<i);

                   cnt++;

                 }

                 else if(cnt >= )

                 {

                     ans2 = ans2|((long long)<<i);

                     cnt++;

                 }

             }

             else

             {

                 if(cnt>)

                 {

                     ans1 = ans1|((long long)<<i);

                     ans2 = ans2|((long long)<<i);

                 }

             }

         }

         if(ans2<l)

         {

             if(l%==)

                 printf("1\n2\n%I64d %I64d\n",l,l+);

             else printf("1\n2\n%I64d %I64d\n",l+,l+);

         }

         else printf("0\n3\n%I64d %I64d %I64d\n",ans1,ans2,r);

     }

     }

     else

     {

         int count1 = ;

         long long tem1 = r;

         while(tem1>)

         {

             tem1 = tem1>>;

             count1++;

         }

         //cout<<count1<<endl;

         int cnt = ;

         long long ans1 = ;

         long long ans2 = ;

         for(int i = count1-;i>=;i--)

         {

             if(((r>>i)&)==)

             {

                 if(cnt == )

                 {

                   ans1 = ans1|((long long)<<i);

                   cnt++;

                 }

                 else if(cnt >= )

                 {

                     ans2 = ans2|((long long)<<i);

                     cnt++;

                 }

             }

             else

             {

                 if(cnt>)

                 {

                     ans1 = ans1|((long long)<<i);

                     ans2 = ans2|((long long)<<i);

                 }

             }

             //cout<<ans2<<' '<<ans1<<endl;

         }

         //cout<<ans2<<' '<<ans1<<endl;

         if(ans2<l)

         {

             if(l%==)

                 printf("1\n2\n%I64d %I64d\n",l,l+);

             else printf("1\n2\n%I64d %I64d\n",l+,l+);

         }

         else printf("0\n3\n%I64d %I64d %I64d\n",ans1,ans2,r);

     }

     return ;

 }

Codeforces Round #262 (Div. 2) 1004的更多相关文章

  1. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  2. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  3. codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...

  4. Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力

    E. Roland and Rose Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  5. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

  6. Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

    题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...

  7. Codeforces Round #262 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  8. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  9. Codeforces Round #262 (Div. 2) 二分+贪心

    题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...

随机推荐

  1. 【WPF系列】基础学习-XAML

    引言 WPF框架中已经提到,WPF框架提供XAML基本服务.WPF中XAML的引入向开发者提供UI设计和代码分离的编程型.XAML是WPF中提出的一个具有重要意义的新技术,基本涉及WPF中所有UI开发 ...

  2. 百度地图API显示多个标注点并添加百度样式检索窗口

    原作者博客地址:http://blog.csdn.net/a497785609/article/details/24009031 在此基础上进行了修改: 1.添加闭包,将i传入内部 2.添加地图和卫星 ...

  3. 【JavaScript 插件】实现图片倒影效果 - reflex.js

    目前版本: reflex.js 1.5 适用的主流浏览器: Mozilla Firefox 1.5+, Opera 9+, Safari and IE6+ 原理:通过 canvas 重画图片,显示倒影 ...

  4. sublime 安装笔记

    sublime 安装笔记 下载地址 安装package control 根据版本复制相应的代码到console,运行 按要求重启几次后再按crtl+shift+p打开命令窗口 输入pcip即可开始安装 ...

  5. HTML 学习笔记 JavaScript(数组)

    1.数组的创建 var arrayObj = new Array(); //创建一个数组var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限,是 ...

  6. SQLMAP大全

    转自:http://blog.csdn.net/zsf1235/article/details/50974194 本人小白,初次认识sqlmap,很多都是转载资料,只是学习研究一下! 练习的网站可以用 ...

  7. JSP之WEB服务器:Apache与Tomcat的区别 ,几种常见的web/应用服务器

    注意:此为2009年的blog,注意时效性(针对常见服务器)     APACHE是一个web服务器环境程序 启用他可以作为web服务器使用 不过只支持静态网页 如(asp,php,cgi,jsp)等 ...

  8. Log4j的ConversionPattern参数的格式含义

    Log4j建议只使用四个级别,优先级从高到低分别是ERROR.WARN.INFO.DEBUG#这里定义能显示到的最低级别,若定义到INFO级别,则看不到DEBUG级别的信息了~!log4j.rootL ...

  9. a版本冲刺第七天

    队名:Aruba   队员: 黄辉昌 李陈辉 林炳锋 鄢继仁 张秀锋 章  鼎 学号 昨天完成的任务 今天做的任务 明天要做的任务 困难点 体会 408 学习活动的消息传递和日志分析 因为大家都在赶进 ...

  10. BZOJ1572 工作安排 USACO2009

    描述 Description     Farmer John 有太多的工作要做啊!!!!!!!!为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间.他的工作日从0时刻开始,有100000 ...