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. iOS_02_第一个C语言程序(理解编译、连接、运行)

    一.开发工具的选择 1. 可以用来写代码的工具:记事本.ULtraEdit.Vim.Xcode等. 2. 选择XCode的原因:苹果公司官方提供的开发利器.简化开发的工程.有高亮显示功能. 3. 使用 ...

  2. 【Codeforces Round #445 (Div. 2) C】 Petya and Catacombs

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看时间戳为i的点有哪些. 每次优先用已经访问过的点. 如果不行就新创一个点. 注意新创点的时间戳也是i. [代码] #includ ...

  3. 【】minimum

    [链接]h在这里写链接 [题意] 给两个数字a,b,每次操作可以把a+1a+1,或把a∗k 问至少多少次操作可以使得a=b. 1<=a,b<=10^18,0 <= k <= 1 ...

  4. ElasticSearch 2.4

    ES是一个基于Lucene的分布式全文搜索服务器,和SQL Server的全文索引(Fulltext Index)有点类似,都是基于分词和分段的全文搜索引擎,具有分词,同义词,词干查询的功能,但是ES ...

  5. OC学习篇之---Foundation框架中的其他类(NSNumber,NSDate,NSExcetion)

    1.NSNumber 这个类主要是用来封装基本类型的,说到这里,就不得不说一下了: OC中的集合是不允许存入基本类型的,所以NSNumber类就诞生了,需要将基本类型封装一下,然后存进去,这个类似于J ...

  6. OC学习篇之---Foundation框架中的NSObject对象

    从这篇文章开始我们开始介绍Foundation框架. OC中的Foundation框架是系统提供了,他就相当于是系统的一套api,和Java中的一些系统jar很相似,又早起的一批人开发的,内部有很多现 ...

  7. 【Codeforces Round #437 (Div. 2) B】Save the problem!

    [链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A ...

  8. [Angular] Implementing A General Communication Mechanism For Directive Interaction

    We have modal implement and now we want to implement close functionality. Becuase we use a structure ...

  9. 结合Wireshark捕获分组深入理解TCP/IP协议栈之HTTP协议

    摘要:     本文简单介绍了Web应用层协议理论知识,详细讲述了HTTP请求报文和响应报文各个字段含义,并从Wireshark俘获分组中选取HTTP相关报文进行分析. 一.概述     Web的应用 ...

  10. get_slave_status.py

    #!/usr/bin/env python#-*- encoding: utf8 -*- import mysql.connectorimport get_mysql_conn_info    &qu ...