Codeforces 460D. Little Victor and Set
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
1
2
10 11
8 30 7
0
5
14 9 28 11 16
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的更多相关文章
- Codeforces 460D Little Victor and Set(看题解)
Little Victor and Set 其他都很好求, 只有k == 3的时候很难受.. 我们找到第一个不大于l的 t, 答案为 l, 3 * t, (3 * t) ^ l 感觉好像是对的, 感觉 ...
- Codeforces 460D Little Victor and Set --分类讨论+构造
题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...
- codeforces 460D Little Victor and Set(构造、枚举)
最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...
- 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 ...
- 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 ...
- 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 ...
- 【递推】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& ...
- 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?
题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...
- 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 ...
随机推荐
- Oracle数据库学习(四)
11.创建表 crate table tab1(f_id number not null,f_a varchar2(7) not null,f_b number(6,2) not null): 主键: ...
- Android驱动开发5-7总结
Android深度探索5-7章总结 介绍了S3C6410开发板的功能,开发板的不同主要是在烧录嵌入式系统的方式不同,以及如何在此开发板上安装Android.紧接着学到介绍到如何在多种平台,使用多种方式 ...
- Python知识点入门笔记——基本运算和表达式
变量:Python的变量不需要单独定义,直接在赋值的过程中完成定义. 当直接运行一个没有赋值过的变量时,会报错. 当不需要某个变量时,可以用del来删除 每个变量都占据着一定的内存空间,当变量被删除了 ...
- 学习Spring框架系列(一):通过Demo阐述IoC和DI的优势所在
Spring框架最核心东西便是大名鼎鼎的IoC容器,主要通过DI技术实现.下面我通过Demo的演变过程,对比学习耦合性代码,以及解耦和的过程,并深入理解面向接口编程的真正内涵. 这个例子包括如下几个类 ...
- 自定义RadioGrop,支持添加包裹着的RadioButton
控件类: package com.chinaCEB.cebView; import android.annotation.TargetApi; import android.content.Conte ...
- springboot学习资料汇总
收集Spring Boot相关的学习资料,Spring Cloud点这里 推荐博客 纯洁的微笑 程序猿DD liaokailin的专栏 Spring Boot 揭秘与实战 系列 catoop的专栏 简 ...
- 设计模式之第19章-中介者模式(Java实现)
设计模式之第19章-中介者模式(Java实现) “测试妹纸找你,你的代码出问题了.”“美工妹纸让你看看界面怎么样.”身为程序员总要和各种人打交道,但是如果再分为前端.后端工程师的话,那么关系就会错综复 ...
- 【BZOJ 3620】似乎在梦中见过的样子
题目 (夢の中で逢った.ような--) 「Madoka,不要相信 QB!」伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Modoka 的一个噩梦,也同时是上个轮回中所发 ...
- 再写一篇tps限流
再写一篇tps限流 各种限流算法的称呼 网上有很多文章介绍限流算法,但是对于这些算法的称呼与描述也是有点难以理解.不管那么多了.我先按我理解的维度梳理一下. 主要维度是:是正向计数还是反向计数.是定点 ...
- Java类和对象 详解(一)---写的很好通俗易懂---https://blog.csdn.net/wei_zhi/article/details/52745268
https://blog.csdn.net/wei_zhi/article/details/52745268