time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations:

multiply the current number by 2 (that is, replace the number x by 2·x);

append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1).

You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.

Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.

Input

The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.

Output

If there is no way to get b from a, print “NO” (without quotes).

Otherwise print three lines. On the first line print “YES” (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, …, xk, where:

x1 should be equal to a,

xk should be equal to b,

xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k).

If there are multiple answers, print any of them.

Examples

input

2 162

output

YES

5

2 4 8 81 162

input

4 42

output

NO

input

100 40021

output

YES

5

100 200 2001 4002 40021

【题解】



有两个操作*2,*10+1,不管是哪个操作。最后的总操作数都不会很大。

毕竟是log2,log10级别的。开个1W肯定不会有事了。

然后就深搜啦。因为题目强行降低难度,不要最短着。所以随便搜了。

还是加了个map判重来优化。

#include <cstdio>
#include <map>
#define LL long long using namespace std;
LL a, b;
map <LL, int> frequent;
LL ans[10000] = { 0 };
int maxl = 0; bool dfs(LL key, int now)
{
if (frequent[key]==1)
return false;
frequent[key] = 1;
if (key > b)
return false;
if (key == b)
{
ans[now] = key;
maxl = now;
return true;
}
//*2
bool temp;
temp = dfs(key * 2, now + 1);
if (temp)
{
ans[now] = key;
return true;
}
temp = dfs(key * 10 + 1, now + 1);
if (temp)
{
ans[now] = key;
return true;
}
return false;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
scanf("%I64d%I64d", &a, &b);
if (dfs(a, 1))
{
puts("YES");
ans[1] = a;
printf("%d\n", maxl);
printf("%I64d", a);
for (int i = 2; i <= maxl; i++)
printf(" %I64d", ans[i]);
printf("\n");
}
else
puts("NO");
return 0;
}

【35.56%】【727A】Transformation: from A to B的更多相关文章

  1. NOIP2017 列队 题解报告【56行线段树】

    题目描述 Sylvia 是一个热爱学习的女♂孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia 所在的方阵中有n \times mn×m名学生,方阵的行数 ...

  2. UI设计师零基础入门到精通精品视频教程【155课高清完整版】

    [福吧资源网分享]课程是非常完整的,也是非常零基础的,适合任何学员,有需要的可以下载看看!课程目录:第1章 Adobe Photoshop CS6课时1 Adobe Photoshop CS6入门基础 ...

  3. 【Android】【录音】Android录音--AudioRecord、MediaRecorder

    [Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...

  4. 【剑指Offer学习】【全部面试题汇总】

    剑指Offer学习 剑指Offer这本书已经学习完了.从中也学习到了不少的东西,如今做一个总的文件夹.供自已和大家一起參考.学如逆水行舟.不进则退.仅仅有不断地学习才干跟上时候.跟得上技术的潮流! 全 ...

  5. 【Xamarin开发 Android 系列 3】循序渐进的学习顺序

    原文:[Xamarin开发 Android 系列 3]循序渐进的学习顺序 指定合理的学习步骤,将各个技术点进行强化.慢慢 的就从点到线 到面的飞跃,一切仅仅是时间问题,开始前,请记住,学习是最佳的投资 ...

  6. 【iScroll源码学习01】准备阶段 - 叶小钗

    [iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文  http://www.cnblogs.com/yexiaochai/p/3 ...

  7. 【剑指Offer学习】【所有面试题汇总】

    剑指Offer学习 剑指Offer这本书已经学习完了,从中也学习到了不少的东西,现在做一个总的目录,供自已和大家一起参考,学如逆水行舟,不进则退.只有不断地学习才能跟上时候,跟得上技术的潮流! 所有代 ...

  8. 【Python】【容器 | 迭代对象 | 迭代器 | 生成器 | 生成器表达式 | 协程 | 期物 | 任务】

    Python 的 asyncio 类似于 C++ 的 Boost.Asio. 所谓「异步 IO」,就是你发起一个 IO 操作,却不用等它结束,你可以继续做其他事情,当它结束时,你会得到通知. Asyn ...

  9. 【Python】【有趣的模块】tqdm | inspect

    tqdm """ [tqdm] 显示循环的进度条,再也不用担心程序跑到哪里还要跑多久了 tqdm 可以直接包裹iterable对象 from tqdm import tq ...

随机推荐

  1. 【转】排列组合 "n个球放入m个盒子m"问题 总结

    出处:https://blog.csdn.net/qwb492859377/article/details/50654627 球,盒子都可以分成是否不能区分,和能区分,还能分成是否能有空箱子,所以一共 ...

  2. 全面详细介绍一个P2P网贷领域的ERP系统的主要功能

        一般的P2P系统,至少包括PC网站的前端和后端.前端系统的功能,可以参考"P2P系统哪家强,功能其实都一样" http://blog.csdn.net/fansunion/ ...

  3. 关于stm32的输入输出

    https://blog.csdn.net/u011556018/article/details/72629082

  4. 18.1 IIC驱动程序(基于3.4.2内核)

    驱动使用smbus提供的IIC读写函数可以参考smbus-protocol.txt文档:应用层直接使用IIC读写函数读写IIC设备,应用层读写函数是由i2c-tools这个库提供的(编译的使用和应用程 ...

  5. LIVE555源代码研究之四:MediaServer (一)

    LIVE555源代码研究之四:MediaServer (一) 从本篇文章開始我们将从简单server程序作为突破点,深入研究LIVE555源代码. 从前面的文章我们知道.不论什么一个基于LIVE555 ...

  6. crontab经验 分类: B3_LINUX 2015-03-06 11:17 282人阅读 评论(0) 收藏

    1.基本格式  第1列分钟1-59  第2列小时1-23(0表示子夜)  第3列日1-31  第4列月1-12  第5列星期0-6(0表示星期天)  第6列要运行的命令 2.关于日志 (1)基本日志位 ...

  7. angular表单的使用实例

    原文 https://www.jianshu.com/p/da1fd5396798 大纲 1.模板驱动表单的创建 2.响应式表单的创建 3.模板驱动型表单的自定义指令 4.响应式表单的自定义指令 5. ...

  8. blob-照片转换与展示

    File转java.sql.Blob(照片)Struts2 public Blob photos(File zp) { Blob photo=null; try { FileInputStream f ...

  9. iOS开发Quartz2D之 七:雪花效果

    #import "VCView.h" @implementation VCView -(void)awakeFromNib { //[NSTimer scheduledTimerW ...

  10. [React] Update Component State in React With Ramda Lenses

    In this lesson, we'll refactor a React component to use Ramda lenses to update our component state. ...