1. 程式人生 > >Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A

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

turn quotes eba i++ lac from positive 題意 seq

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 x

1,?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 }

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