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. 【转】qqface使用实例

    原网址:http://www.xwcms.net/js/bddm/51565.html <div id="show"></div>   <div cl ...

  2. Spark学习之Spark SQL(8)

    Spark学习之Spark SQL(8) 1. Spark用来操作结构化和半结构化数据的接口--Spark SQL. 2. Spark SQL的三大功能 2.1 Spark SQL可以从各种结构化数据 ...

  3. js获取select选中的标签option的值

      js中获取方法 var obj = document.getElementByIdx_xx_x(”testSelect”); //定位id var index = obj.selectedInde ...

  4. 一台机器运行多个JBoss多实例

    JBossXMLJVMTomcat应用服务器  我们经常会遇到这种情况,有时候希望在同一台机器上部署若干个JBoss实例,上面运行不同的应用程序,这样的话无论由于什么原因需要对某个JBoss实例进行关 ...

  5. 迅为7寸Android嵌入式安卓触摸屏,工业一体机方案

    嵌入式安卓触摸屏板卡介绍-工业级核心板: 嵌入式安卓触摸屏功能接口介绍: 品质保障: 核心板连接器:进口连接器,牢固耐用,国产连接器无法比拟(为保证用户自行设计的产品品质,购买核心板用户可免费赠送底板 ...

  6. 迅为I.MX6DL开发板飞思卡尔Freescale Cortex A9 迅为-iMX6双核核心板

    核心板参数 尺寸: 51mm*61mm CPU: Freescale Cortex-A9 双核精简版 i.MX6DL,主频 1.2 GHz 内存: 1GB DDR3 存储: 8GB EMMC 存储 E ...

  7. 01Hibernate

    Hibernate Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自 ...

  8. Jedis集成到项目中

    Jedis整合到项目中,就可以在项目中使用redis了,作为Java程序狗,这个可以会,贴代码了,不截图了,哈哈 一.maven中的pom.xml中添加依赖 <dependency> &l ...

  9. tinyXml输出utf-8文档

    TiXmlDocument虽然能读取utf-8的xml文件,但读入后在内存中是以多字节存储.如果新建一个TiXmlDocument,即使定义头为utf-8编码,直接调用SaveFile方法保存的文档仍 ...

  10. IO之DataStream数据流举例

    import java.io.*; public class TestDataStream { public static void main(String[] args) { ByteArrayOu ...