【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两种颜色的格子; 让你在这个格子 ...
随机推荐
- js中return 、return false 、return true、break、continue区别
在开发中不熟悉这三者区别的同学,一般都知道return可以中止,但会根据字面意思觉得return true 中止当前函数执行,但其后的函数还会继续执行.return false 中止当前函数执行,其后 ...
- 关于common.js里面的module.exports与es6的export default的思考总结
背景 公司项目需要裁切功能,基于第三方图片裁切组件vue-cropper(0.4.0版本),封装了图片裁切组件(picture-cut)(放在公司内部组件库,仅限于公司内部使用) 在vue-cropp ...
- BZOJ 1176[Balkan2007]Mokia(CDQ分治)
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 3381 Solved: 1520[Submit][S ...
- 极速响应Excel数据报表请求的一种方法
摘要 通过缓存和维护Excel Workbook实例,极速响应Excel数据报表请求. 这是一个真实的大数据"云计算"项目中的解决方案,在给定的时间和资源下,只有这种方法是最简单并 ...
- Unity调用Android的两种方式:其一、调用jar包
unity在Android端开发的时候,免不了要调用Java:Unity可以通过两种方式来调用Android:一是调用jar.二是调用aar. 这篇文章主要讲解怎么从无到有的生成一个jar包,然后un ...
- 【DevExpress】GridControl添加按钮列并添加按钮事件
在GridControl中添加按钮列的步骤如下: 1. 把列的ColumnEdit属性设置为RepositoryItemButtonEdit 2. 把TextEditStyle属性设置为HideTex ...
- ArcGIS api for javascript——鼠标悬停时显示信息窗口
描述 本例展示当用户在要素上悬停鼠标时如何显示InfoWindow.本例中,要素是查询USA州图层的QueryTask的查询结果.工作流程如下: 1.用户单击一个要素 2.要素是“加亮的”图形. 3. ...
- [React] Make Controlled React Components with Control Props
Sometimes users of your component want to have more control over what the internal state is. In this ...
- mysql python中的pymysql模块使用
import pymysql # 在这之前需要给mysql授登录权限 grant all on "; 否则会导致连接时出错 # flush privileges; #创建连接 conn = ...
- 第四次python作业——叶耀宗
设计题2: 1.参考“三国演义”词频统计程序,实现对红楼梦出场人物的频次统计.2.(可选)将红楼梦出场人物的频次统计结果用词云显示. import jieba excludes = {"什么 ...