【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

把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的更多相关文章

  1. 【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)) 然后其他 ...

  2. 【Codeforces Round #457 (Div. 2) A】 Jamie and Alarm Snooze

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力往前走x分钟就好. 直到出现7为止. [代码] #include <bits/stdc++.h> using nam ...

  3. 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...

  4. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  5. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  6. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

随机推荐

  1. 3065: 带插入区间K小值_树套树_替罪羊树_权值线段树

    经过周六一天,周一3个小时的晚自习,周二2个小时的疯狂debug,终于凭借自己切掉了这道树套树题. Code: #include <cstdio> #include <algorit ...

  2. Mac sublime快捷键操作

    1.打开命令面板 command + shift + p 2.打开关闭side bar command + k , command + b 3.打开新sublime窗口 command + shift ...

  3. 到2023年将会有超过90%的PC采用SSD硬盘

    本文转载自超能网,其他媒体转载需经超能网同意 现在买电脑或者自己装机,还有谁不要SSD硬盘吗?这个问题似乎没什么可说的,SSD硬盘各种好,装机可以说是必选了,但实际上现在的SSD适配率并没有想象中那么 ...

  4. uwsgi erro

    Installing collected packages: uwsgi Running setup.py install for uwsgi: started Running setup.py in ...

  5. caioj 1111 树形动态规划(TreeDP)6: 皇宫看守 (状态设计)

    这道题的难点在于状态怎么设计 这道题要求全部都是安全的,所以我们做的时候自底向上每一个结点都要是安全的 结合前一题当前结点选和不选,我们可以分出四种情况出来 选 安全 选 不安全 不选 安全 不选 不 ...

  6. 紫书 习题 10-7 UVa 10539(long long + 素数筛)

    注意要开long long 如果int * int会炸 那么久改成long long * int #include<cstdio> #include<vector> #incl ...

  7. ArcGIS api for javascript——渲染-使用唯一值渲染

    描述 本例使用唯一值渲染器来作为美国的符号.每个州有一个字符串属性"SUB_REGION"表示它的国家的地区.UniqueValueRenderer.addValue()方法被用来 ...

  8. OpenStack云桌面系列【1】—開始

    关于"云桌面"和"桌面云" 首先,wiki里面是没有关于"桌面云"和"云桌面"的定义和其他信息.     百度百科   ...

  9. Install Qt 5 on Ubuntu(使用qt-opensource-linux-x64-5.7.0.run进行安装,而且是官方的wiki)

    Introduction This is a tutorial for installation of Qt 5.7.0 to Ubuntu 12.10. It may be used also fo ...

  10. vue12 循环添加重复数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...