码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-07-27 01:01:56      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:mini   iostream   bsp   from   ace   logs   输出   otherwise   i++   

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 }

 

 

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

标签:mini   iostream   bsp   from   ace   logs   输出   otherwise   i++   

原文地址:http://www.cnblogs.com/yinghualuowu/p/7242425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!