题目连接: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. Vue中使用vux的配置

    一.根据vux文档直接安装,无需手动配置 npm install vue-cli -g // 如果还没安装 vue init airyland/vux2 my-project // 创建名为 my-p ...

  2. 下拉刷新和UITableView的section headerView冲突的原因分析与解决方案

    UITableView:下拉刷新和上拉加载更多 [转载请注明出处] 本文将说明具有多个section的UITableView在使用下拉刷新机制时会遇到的问题及其解决方案. 工程地址在帖子最下方,只需要 ...

  3. gcc 随笔

    将几个文件编译成一个动态库 libtest.so gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so 将test.c与动态库libte ...

  4. 实现字符串检索strstr函数、字符串长度strlen函数、字符串拷贝strcpy函数

    #include <stdio.h> #include <stdlib.h> #include <string.h> /* _Check_return_ _Ret_ ...

  5. Django之jsonp跨域请求原理

    在进行网站开发的过程中经常会用到第三方的数据,但是由于同源策略的限制导致ajax不能发送请求,因此也无法获得数据.解决ajax的跨域问题有两种方法: 一.jsonp 二.XMLHttpRequest2 ...

  6. VMware 克隆多台Linux机器并配置IP的方法

    我们首先要知道 VMware 三种网络模式的区别. ①.Bridged(桥接模式):就是将主机网卡与虚拟机虚拟的网卡利用虚拟网桥进行通信.在桥接的作用下,类似于把物理主机虚拟为一个交换机,所有桥接设置 ...

  7. KS(Kolmogorov-Smirnov)(转)

    来源:https://blog.csdn.net/u013421629/article/details/78217498 KS(Kolmogorov-Smirnov):KS用于模型风险区分能力进行评估 ...

  8. UBIFS学习笔记

    在做项目的时候,发现flash芯片有异常现象,经过打印分析,发现是UBIFS方面设置有一些问题,经过查阅一部分资料,最终得到问题的答案. 在解决问题的过程中,发现打印信息比较重要,但网上并没有直接的相 ...

  9. PDFRender4NET的使用之pdf转图片

    同样的需要第三方的.dll,http://www.o2sol.com/pdfview4net/download.htm using O2S.Components.PDFRender4NET; usin ...

  10. Nginx - 隐藏或修改版本号

    1. 前言 无论是修改 Nginx 版本还是隐藏 Nginx 版本号,都是很简单的操作,对外来说,相对更安全些. 2. 修改 Nginx 版本号 对于修改 Nginx 版本号来说,需要在源码的基础上进 ...