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. JS实现动画方向切换效果(包括:撞墙反弹,暂停继续左右运动等)

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. Android新控件RecyclerView剖析

    传智·没羽箭(传智播客北京校区Java学院高级讲师) 个人简单介绍:APKBUS专家之中的一个,黑马技术沙龙会长,在移动领域有多年的实际开发和研究经验.精通HTML5.Oracle.J2EE .Jav ...

  3. AndroidActivity跳转动画,让你的APP瞬间绚丽起来

    我们都知道绚丽的APP总会给用户耳目一新的感觉,为了抓住用户更大网络公司使出浑身解数让自己的产品更绚丽,而绚丽最简单的效果就是Activity跳转效果,不仅能够让用户看起来舒服,并且实现起来也特别简单 ...

  4. flask的使用(一)

    1.程序基本的说明 #-*-encoding=utf--*- 从flask中引入类 from flask import Flask ,render_template import config 初始化 ...

  5. 使用wepy开发微信小程序商城第一篇:项目初始化

    使用wepy开发微信小程序商城 第一篇:项目初始化 前言: wepy小程序项目初始化的操作,官方文档看了好几遍,感觉写得不是很清楚. 这篇写得挺好的:小程序开发之wepy 1.初始化项目 (1)全局安 ...

  6. [WASM] Compile C Code into WebAssembly

    We use the C language instead of pure WAST to create a square root function using WASM Fiddle (https ...

  7. 28、应用调试之strace命令来跟踪系统调用

    strace是个工具,在使用时需要先按照,见韦东山书籍: 1.tar xjf starce-4.5.15.tar.bz2 2.cd strace-4.5.15/ 3.patch -p1 < .. ...

  8. 【rlz02】二进制转十进制

    Time Limit: 3 second Memory Limit: 2 MB 问题描述 输入一个二进制数,编程转换为十进制数. 整数部分不会超过65535,二进制的小数部分不会超过4位. Sampl ...

  9. [Angular2 Form] Nested formGroup, and usage of formGroupName

    We can nest formGorup: this.reactiveForm = fb.group({ username: [ '', [ Validators.required, Validat ...

  10. BAPC2014 C&amp;&amp;HUNNU11583:Citadel Construction(几何)

    题意: 给出一系列的点,要求寻找最多4个点.使得组成一个面积最大的多边形 思路: 非常显然仅仅有两种情况.要么是三角形,要么是四边形 首先不难想到的是.先要把最外面的点都找出来,事实上就是找凸包 可是 ...