题目连接: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. 高可用rabbitmq集群服务部署步骤

    消息队列是非常基础的关键服务,为保证公司队列服务的高可用及负载均衡,现通过如下方式实现: RabbitMQ Cluster + Queue HA + Haproxy + Keepalived 3台ra ...

  2. 无密码ssh登录linux

    简介 ssh是常见的远程登录linux的方式,大部分时候需要输入用户名密码登录.本文介绍如何无密码登录linux,适用于mac和linux,windows不清楚. 不过这不是什么新的知识,基本上大家都 ...

  3. nginx 与 tomcat 组合搭建web服务

    部分内容转自 http://www.cnblogs.com/naaoveGIS/ 1. Web服务 nginx是常用的web服务器,用于获取静态资源,类似的服务器还有apache. tomcat是基于 ...

  4. POJ 1228 Grandpa's Estate 凸包 唯一性

    LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...

  5. oozie的简易安装

    1. 解压  tar -zxvf oozie-4.0.0-cdh5.3.6.tar.gz 2.配置hadoop的集群,添加一个代理用户(给oozie运行mapreduce的权限) 在hadoop的co ...

  6. kali2.0安装虚拟机工具

    kali2.0无法安装虚拟机工具,显示VMware Tools无法用于该虚拟机,或者安装之后无法进行复制.粘贴等操作. 解决办法: step1: 更换源 root@starnight:~# vim / ...

  7. 记一次powershell反混淆(2)

    样本地址 https://www.hybrid-analysis.com/sample/4b4b8b13c264c8f7d7034060e0e4818a573bebc576a94d7b13b4c174 ...

  8. 转一篇:Reactor模式

    转载自:http://www.blogjava.net/DLevin/archive/2015/09/02/427045.html 前记 第一次听到Reactor模式是三年前的某个晚上,一个室友突然跑 ...

  9. linux系统分区参考

    UPDATE: update is used to download package information from all configured sources. UPGRADE:  upgrad ...

  10. ltib安装过程中遇到好多问题,从网上转来的好多份总结

    最近调试MPC5125的板子,第一步LTIB都装不过去,挫败感十足. LTIB的安装镜像来自于freescale的ltib-mpc5121ads-200906,是用于Ubuntu 10版本之前的,现在 ...