题目连接:http://codeforces.com/contest/727/problem/A

A. Transformation: from A to B
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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
YES52 4 8 81 162 
input
4 42
output
NO
input
100 40021
output
YES5100 200 2001 4002 40021 

题目大意:给定一个数n,有两种操作,使其变成给定的目标数。

操作1:变为原来的两倍,即变为2*n,操作2:乘10加1,即变为n*10+1。

若能通过这两种操作变为给定的目标数,则输出yes,并输出变化路径。

解题思路:

没有要求最小变化,所以简单dfs即可,路径利用dfs特性储存在数组即可,路径数组大小考虑一下最坏情况即可(一直乘2,数据范围10^9,大约是2^30)

代码如下:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

];
int x;

bool dfs(ll n,int r, ll s)
{
    if(n==s)
        return true;
    if(n>s)
        return false;
    lu[r]=n;
    r++;
    x=r;
    +,r,s))
        return true;
    ,r,s))
        return true;
    return false;
}

int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ,b))
    {
        lu[x]=b;
        x++;
        cout<<"YES"<<endl;
        cout<<x<<endl;
        ;i<x;i++)
            cout<<lu[i]<<" ";
    }
    else
        cout<<"NO"<<endl;
}

codeforces-727A的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

  10. CodeForces - 453A Little Pony and Expected Maximum

    http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...

随机推荐

  1. zkw费用流 学习笔记

    分析 记\(D_i\)为从\(S\)出发到\(i\)的最短路 最短路算法保证, 算法结束时 对于任意存在弧\((i,j)\)满足\(D_i + c_{ij}\ge D_j\) ① 且对于每个 \(j\ ...

  2. 搜索:DLX算法

    精确覆盖问题:在一个0-1矩阵中,选定部分行,使得每一列都有且只有一个1.求解一种选法 舞蹈链(Dance Link),也就是一个循环十字链表,可以快速的删掉和恢复某行某列 结合了舞蹈链的搜索就称作D ...

  3. 关于 Capella 需要纠正的语音

    li { font-size: 18px; } 关于 Capella 需要纠正的语音 持续更新 浊塞音声带要振动 区分 [θ]/[ð] 和 [t̪],注意舌位 [ɫ] 的舌位,切记不能圆唇 [æ] 的 ...

  4. [php]unset函数

    unset($var); 释放一个变量空间 unset($var1, $var2...);释放多个变量空间 unset(var['数组元素内容']);释放数组元素 注意: 1.在函数内部释放全局变量和 ...

  5. 【BZOJ】2693: jzptab 莫比乌斯反演

    [题意]2154: Crash的数字表格 莫比乌斯反演,多组询问,T<=10000. [算法]数论(莫比乌斯反演) [题解]由上一题, $ans=\sum_{g\leq min(n,m)}g\s ...

  6. lintcode 40. 用栈实现队列

    使用两个栈来回倒腾可以实现队列. AC代码: import java.util.Stack; public class Queue { private Stack<Integer> sta ...

  7. 爬虫实战--基于requests 和 Beautiful的7160美图网爬取图片

    import requests import os from bs4 import BeautifulSoup import re # 初始地址 all_url = 'http://www.7160. ...

  8. ACM-ICPC北京赛区2018重现赛 A题

    题目链接:http://hihocoder.com/contest/icpcbeijing2018/problem/1 具体思路:dfs,判断矛盾就可以了. AC代码: #include<ios ...

  9. Test plan

    Options for Test Strategy: 1. Regular test: all the planned test cases will be executed 2. Extented ...

  10. Supply

    Supplier创建一个Supply Supply有tap或emit方法. 可以这样理解: Supplier创建一个工厂 Supply 用tap创建流水线 emit向流水线上传送加工品进行加厂 my ...