zoukankan      html  css  js  c++  java
  • Technocup 2017

    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 }
  • 相关阅读:
    父容器直接清除浮动的css
    [原创 js]指定DOM中添加字符串函数
    跨浏览器的透明度解决方案(包括IE8 Beta 2)
    [原创 js]验证表单强度的js
    帧率、码流与分辩率之间关系
    隔行扫描和逐行扫描(interlace and progressive )
    VGA管脚定义
    红眼消除
    HDMI_VGA_CBVS同时显示
    分辨率与行场同步信号的关系
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7242425.html
Copyright © 2011-2022 走看看