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

【题意】

在这里输入题意

【题解】

把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. [国家集训队]整数的lqp拆分 数学推导 打表找规律

    题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...

  2. [NOI2010]海拔 平面图转对偶图 最小割

    题解: 首先,我们不难猜到高度只有 $0$ 或 $1$ 两种可能,而且高度为 0 的地区组成一个联通块,高度为 1 的地区组成一个联通块.只有这样,人们所耗费的体力才是最小的.得出这个结论,题目就成了 ...

  3. 在 yii2.0 框架中封装导出html 表格样式 Excel 类

    在 vendor/yiisoft/yii2/helpers/ 创建一个 Excel.php <?php namespace yii\helpers;   class Excel{         ...

  4. NodeJS学习笔记 进阶 (8)express+morgan实现日志记录(ok)

    个人总结:这篇文章讲解了Express框架中日志记录插件morgan的示例.读完这篇文章需要10分钟 摘选自网络 章节概览 morgan是express默认的日志中间件,也可以脱离express,作为 ...

  5. Incermental GC

    目录 增量式垃圾回收 什么是增量式垃圾回收 三色标记算法 GC 标记清除算法的分割 根查找阶段 标记阶段 写入屏障 清除阶段 分配 优点和缺点 缩短最大暂停时间 降低了吞吐量 Steele 的算法 m ...

  6. CRC校验原理及步骤

    什么是CRC校验? CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并 ...

  7. [PostCss] Easily Load Google Fonts with PostCSS Font Magician

    Configuring Google Fonts can be quite an annoying process to setup. Using Font Magician with PostCSS ...

  8. 《Java并发编程实战》第五章 同步容器类 读书笔记

    一.同步容器类 1. 同步容器类的问题 线程容器类都是线程安全的.可是当在其上进行符合操作则须要而外加锁保护其安全性. 常见符合操作包括: . 迭代 . 跳转(依据指定顺序找到当前元素的下一个元素) ...

  9. vector容器的实现

    简单实现了构造.析构.push_back.pop_back.operator=.operator[].clear等函数 template<class T> class my_vector ...

  10. ProFTPD 的 mod_lang模块

    ProFTPD 的 mod_lang模块http://www.proftpd.org/docs/modules/mod_lang.html安装该mod_lang模块随ProFTPD一起分发.要在pro ...