【Codeforces Round #457 (Div. 2) B】Jamie and Binary Sequence
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
把n分解成二进制的形式。
n=2^a0+2^a1+...+2^a[q-1]
则固定就是长度为q的序列。
要想扩展为长为k的序列。
可以把2^x转化为2^(x-1)+2^(x-1)的形式.
这样序列的长度就+1了
它要求max{ai}最小
那么我们可以枚举ai的最大值是什么->i
(递减着枚举)
然后比i大的ai都换成两个ai-1的形式。
然后看看序列的长度是否小于等于k;
如果小于k的话。
就把min{ai}分解成两个min{ai}-1
这样可以尽量让max{ai}==i的情况下,字典序尽量大。
这样长度递增1.
重复上述步骤。直到长度变为k.
然后枚举最大值为i-1,i-2...
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 64;
ll n;
int k,a[N+10];
map<int,ll> cnt,cnt1;
vector<int> v;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> k;
while (n){
a[0]++;
a[a[0]] = n&1;
n>>=1;
}
ll now = 0;
for (int i = a[0];i >= 1;i--)
if (a[i]){
now++;
cnt[i-1]++;
}
for (int j = 0;j<=N;j++) cnt1[j] = cnt[j];
int ma = a[0]-1;
ll tlen = now;
for (int i = ma; ;i--){
cnt.clear();
for (int j = 0;j <= N;j++)
cnt[j] = cnt1[j];
now = tlen;
for (int j=N;j>=i+1;j--){
now+=cnt[j];
cnt[j-1]+=2*cnt[j];
cnt[j] = 0;
}
/*cout <<"i="<<i<<endl;
cout <<now<<endl;
*/
if (now>k) break;
int last = -100000;
while (now<k){
for (int j = last;j <= N;j++){
if (cnt[j]>0){
cnt[j]--;
cnt[j-1]+=2;
now++;
last = j-1;
break;
}
}
}
v.clear();
for (int j = N;j>=last;j--)
for (int l = 1;l <= cnt[j];l++){
v.push_back(j);
}
now = tlen;
}
if (v.empty()){
cout <<"No"<<endl;
}else{
cout <<"Yes"<<endl;
for (int i = 0;i < (int) v.size();i++){
cout <<v[i]<<' ';
}
}
return 0;
}
【Codeforces Round #457 (Div. 2) B】Jamie and Binary Sequence的更多相关文章
- 【Codeforces Round #457 (Div. 2) C】Jamie and Interesting Graph
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比n-1大的最小的素数x 1-2,2-3..(n-2)-(n-1)长度都为1 然后(n-1)-n长度为(x-(n-2)) 然后其他 ...
- 【Codeforces Round #457 (Div. 2) A】 Jamie and Alarm Snooze
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力往前走x分钟就好. 直到出现7为止. [代码] #include <bits/stdc++.h> using nam ...
- 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
随机推荐
- [POI2011]MET-Meteors 整体二分_树状数组_卡常
线段树肯定会 TLE 的,必须要用树状数组. Code: // luogu-judger-enable-o2 #include <cstdio> #include <algorith ...
- MySql系列表之间的关系
foreign key 快速理解foreign key 员工信息表有三个字段:工号 姓名 部门 公司有3个部门,但是有1个亿的员工,那意味着部门这个字段需要重复存储,部门名字越长,越浪费 数据 ...
- 【IDEA】Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compliance level '1.8' or better is required解决办法
在运行的时候常常出现如下错误: Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compl ...
- 题解 P2504 【[HAOI2006]聪明的猴子】
这道题要坑死人啊... 第一次做40分,其他RE,改了一次之后就变成20分了... 究其原因,是有一个数组(dis)开的太小了,于是最后本蒟蒻就随手开了个五百万,然后,就AC了. 看到有一篇题解说求距 ...
- 四 过滤模式 map Only - 作业完成 bloomFilter、top10、去重
第四部分所有的模式涉及一个共同点: 不会改变原有的记录. 这些模式都是寻找数据子集的,不管结果集的规模是小(top10)还是大(像去重结果). 与第三部分差异是,他们通过对数据的相思子端坐概要与分组来 ...
- android 视频开发2分之2(仿美拍,糗百)
上一篇写了分段录制和合并视频.这一篇则是选择视频,然后截断视频. 1.从sdcard中找到视频资源: 2.分析视频,拿到你须要的帧数当你的图片.(我的是依据參数来算的多少秒1帧的图片,通常是1秒1帧来 ...
- sp_executesql invalid object name
https://stackoverflow.com/questions/10417126/dynamically-named-temp-table-returns-invalid-object-nam ...
- Introduction to IIS Architectures
https://docs.microsoft.com/en-us/iis/get-started/introduction-to-iis/introduction-to-iis-architectur ...
- Rapidjson的简单使用示例
很早就想用用Markdown了,一直没机会.今天就来试一下 先放个目录: Rapidjson的简单使用示例 rapidjson官方教程 本示例所用环境 示例代码与注释 rapidjson官方教程 如果 ...
- Git简介以及与SVN的区别
Git是由著名Linux内核(Kernel)开发者LinusTorvalds为了便利维护Linux而开发的. Git是一个分布式的版本控制系统.作为一个分布式的版本控制系统,在Git中并不存在主库这样 ...