Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A

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

题意:就是从a变成b(*2或者的*10+1),可以就输出具体变化

解法:额。。搜索一下嘛

复制代码
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <cstring>
 5 using namespace std;
 6 int a[1000];
 7 long long n,m;
 8 int flag;
 9 int cnt;
10 void dfs(int cnt,long long x){
11 
12     a[cnt]=x;
13     if(x>m){
14         return;
15     }
16     if(x==m&&flag==0){
17         flag=1;
18         cout<<"YES"<<endl;
19         cout<<cnt<<endl;
20         for(int i=1;i<=cnt;i++){
21             cout<<a[i]<<" ";
22         }
23     }
24     dfs(cnt+1,x*10+1);
25     dfs(cnt+1,x*2);
26 }
27 int main(){
28     cin>>n>>m;
29     dfs(1,n);
30     if(flag==0){
31         cout<<"NO"<<endl;
32     }
33     return 0;
34 }
复制代码

 

 

posted @   樱花落舞  阅读(263)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示