博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforce916B
阅读量:6040 次
发布时间:2019-06-20

本文共 2901 字,大约阅读时间需要 9 分钟。

B. Jamie and Binary Sequence (changed after round)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:

Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.

To be more clear, consider all integer sequence with length k (a1, a2, ..., ak) with . Give a value to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.

For definitions of powers and lexicographical order see notes.

Input

The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.

Output

Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.

It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].

Examples
Input
23 5
Output
Yes 3 3 2 1 0
Input
13 2
Output
No
Input
1 2
Output
Yes -1 -1
Note

Sample 1:

23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23

Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.

Answers like (4, 1, 1, 1, 0) do not have the minimum y value.

Sample 2:

It can be shown there does not exist a sequence with length 2.

Sample 3:

Powers of 2:

If x > 0, then 2x = 2·2·2·...·2 (x times).

If x = 0, then 2x = 1.

If x < 0, then .

 

分析:题目有点难懂(-_-#),先把n转换成二进制,如果总长度lenth大于k则不能构成。

因为2x=2x-1+2x-1,即每一位的一个可以转换为低一位的两个,题目要求最高位最小,

那么如果最高位所有的个数转换为下一位后的长度仍<=k,就把最高位全部转为下一位;

否则就不能转换最高位,因为题目要求字典序最大,所以只能转换最低位,每次把最低位

的一个转换为下一位的两个,直到总长度lenth==k。(-_-; )

 

#include
#include
using namespace std;int a[2000000],num[2000000]; const int M=100000;int main(){ long long N,temp; int k; scanf("%lld%d",&N,&k); //M表示0 int len=0,lenth=0; temp=N; while(temp) { a[len+M]=temp%2;len++; if(temp%2) lenth++; temp/=2; } if(lenth>k) {printf("No\n");return 0;} int Max=len+M-1,Min;//最大值下标 for(int i=M;i<=Max;i++) if(a[i]>0) {Min=i;break;} while(true) { if(lenth==k) break; if(a[Max]+lenth>k)//不能再转换 break; a[Max-1]+=a[Max]*2; lenth+=a[Max]; a[Max]=0; Max--; if(Min>Max) Min=Max; } if(lenth
=Min;i--) { while(a[i]) { printf("%d ",i-M); a[i]--; } } printf("\n"); return 0;}
View Code

 

转载于:https://www.cnblogs.com/ACRykl/p/8320898.html

你可能感兴趣的文章
no displays configured
查看>>
小菜鸟从0基础开始学Linux系统
查看>>
反向telnet
查看>>
经典GRE over IPSec实验
查看>>
sudo命令
查看>>
Kvm虚拟机文件转换成Vmware虚拟机文件
查看>>
3322.org ***
查看>>
互联网上的单点登录研究
查看>>
Linux下JDK1.6安装
查看>>
行业音视频通信市场的技术发展
查看>>
mongodb主从,副本集,分片的理解
查看>>
Mongodb语法学习:更新
查看>>
智慧中国杯百万大奖赛解读 | 学霸去哪了(二)
查看>>
小白学习大数据之路——ssh安装及原理
查看>>
ElasticSearch 6.0新特性介绍
查看>>
Java 图片加文字水印以及图片水印 水印位置可选
查看>>
httpClient包实现带hreader和参数的get请求内容为json格式的post请求
查看>>
JavaScript实现连接打印机打印的功能
查看>>
JAVA面向对象之对象和类
查看>>
分享聚能聊"向代码致敬,寻找你的第83行"话题评论截图,得礼品咯!
查看>>