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

Copy
23 5
output
Yes
3 3 2 1 0
input

Copy
13 2
output
No
input

Copy
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 .

Lexicographical order:

Given two different sequences of the same length, (a1, a2, ... , ak) and (b1, b2, ... , bk), the first one is smaller than the second one for the lexicographical order, if and only if ai < bi, for the first i where ai and bi differ.

题意  将一个数n分解成k项 2^a 次幂相加的形式 n=2^a1+2^a2+...+2^ak 那么我们可以得到一个序列a,a中可以有相等的项。求最大值a(max)最小,同时,字典序最大的序列a

解析  用二进制来做,首先要满足最大值最小 如果把当前最大值全部分解为最下一项 时 项数小于等于k 那么就把它分解掉 直到不满足这一条件,因为最大值部分分解掉 a(max)并没有变小

这时候我们就要满足字典序最大,开始分解最小的那一项。

AC代码

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
const int maxn = 1e5+;
const int maxm = 1e4+;
const int inf = 0x3f3f3f3f;
const double epx = 1e-;
typedef long long ll;
const ll INF = 1e18;
int ans[maxn];
int main()
{
map<int,int> ma;
ll n,k;
cin>>n>>k;
priority_queue<int,vector<int>,greater<int> > q;
int cnt=,sum=;
while(n!=)
{
int s=n&;
if(s==)
ma[cnt]++,sum++;
cnt++;
n=n>>;
}
if(k<sum)
printf("No\n");
else
{
printf("Yes\n");
int i;
for(i=;k!=sum;i--)
{
if(ma[i]<=k-sum)
{
ma[i-]+=ma[i]*;
sum+=ma[i];
ma[i]=;
}
else
{
break;
}
}
for(int j=-;j<=;j++)
{
while(ma[j]--)
{
q.push(j);
}
}
if(sum!=k)
{
while(sum!=k)
{
int temp=q.top();
q.pop();
q.push(temp-),q.push(temp-);
sum++;
}
}
int cnt=;
while(!q.empty())
{
ans[cnt++]=q.top();
q.pop();
}
for(int i=cnt-;i>=;i--)
cout<<ans[i]<<" ";
cout<<ans[]<<endl;
}
}

Codeforces Round #457 (Div. 2) B的更多相关文章

  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) B】Jamie and Binary Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把n分解成二进制的形式. n=2^a0+2^a1+...+2^a[q-1] 则固定就是长度为q的序列. 要想扩展为长为k的序列. 可 ...

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

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

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. [转]无废话SharePoint入门教程一[SharePoint概述]

    本文转自:http://www.cnblogs.com/iamlilinfeng/p/3026332.html 一.前言 听说SharePoint也有一段时间了,可一直处在门外.最近被调到ShareP ...

  2. java.lang.String 字符串操作

    1.获取文件名 //获取文件名,即就是去掉文件的后缀 /** * mypic.jpg * 获取文件名 * 1. 先找到"."的位置 * 2. 从第一个字符开始截取到".& ...

  3. VB6程序中NULL注意事项

    VB6中从数据库中取出栏位值进行操作,若栏位值为Null,则必须小心处理,否则极易导致程序出错退出. 通常我们从recordset中取出栏位值采用Fields方法,加上栏位名称,如 rsMoney.F ...

  4. Farseer.net轻量级开源框架 中级篇:探究ORM(Mapping)

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: SQL执行报告 下一篇:Farseer.net轻量级开源框架 中级篇: Cooki ...

  5. spring cloud 概念

    微服务构架需要使用场景: 1.可以将一个系统拆分成几个系统. 2.每个子系统可以部署多个应用,多个应用之间可以使用负载均衡. 3.需要一个服务注册中心,所有的服务都在一个注册中心注册,负载均衡也是通过 ...

  6. docker centos7 配置和宿主机同网段IP

    docker centos7 配置和宿主机同网段IP 1.安装brctl 命令 # yum -y install bridge-utils 2.编辑网卡配置文件 # vi ifcfg-eno16777 ...

  7. Python 反射-isinstance-issubclass-__str__-__del__

    用到的 isinstance(对象,类)  -------------------  判断一个对象是否是一个类的实例 issubclass(子类,父类)  ----------------  判断一个 ...

  8. linux命令 iperf-网络性能测试工具

    博主推荐:更多网络测试相关命令关注 网络测试  收藏linux命令大全 iperf命令是一个网络性能测试工具.iperf可以测试TCP和UDP带宽质量.iperf可以测量最大TCP带宽,具有多种参数和 ...

  9. SSH安全服务

    ssh安全服务     client \ sever     ssh: secure shell, protocol, 22 / tcp, 安全的远程登录, 基于RSA或DSA实现身份认证     两 ...

  10. js ajax 传送xml dom对象到服务器

    客户端代码 1 <script> var isie = true; var xmlhttp = null; function createXMLHTTP() {//创建XMLXMLHttp ...