http://codeforces.com/contest/727/problem/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
YES
5
2 4 8 81 162
Input
4 42
Output
NO
Input
100 40021
Output
YES5100 200 2001 4002 40021 

看到这道题的第一眼,我想到的是用DFS搜索解决,当然搜索完全可以解决.但交上去就出问题了--空间不足--无论怎么优化空间复杂度都会爆栈
最后Lzy突然想到了规律:若某个数是奇数,必然是通过*10+1变来的,而如果某个数是偶数,一定是通过*2得来的.
这样,从b往前倒推,若能得到a,则说明可以,否则不行
#include<iostream>
#include<vector>
#include<stdio.h>
#include<string.h>
#include<stack>
using namespace std;
const int MAXN=;
unsigned int aa[MAXN];
long long a,b;
long long n;
bool flag;
int main()
{
//freopen("data.in","r",stdin);
while(cin>>a>>b) {
flag=;
n=;
aa[]=b;
while(b>) {
if(b==a) {
flag=;
break;
}
if(b%) {
n++;
b=b-;
if(b%)
break;
b=(b/);
aa[n]=b;
} else {
n++;
b=b/;
aa[n]=b;
}
}
if(flag) {
cout<<"YES"<<endl;
cout<<n<<endl;
for(int i=n; i>=; i--) {
cout<<aa[i]<<" ";
}
cout<<endl;
} else cout<<"NO"<<endl;
}
}
												

CodeForces--TechnoCup--2016.10.15--ProblemA--Transformation: from A to B的更多相关文章

  1. My latest news (--2016.10)

    2016.10.31 22:44 一个“程序”,打代码占40%.思考占60% 2016.10.30 20:53 周末,话说今天有晚上讲座,还点名,了,悲催.之前学习的Qt有点问题,悲催.推荐个博文:h ...

  2. 2016 10 28考试 dp 乱搞 树状数组

    2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了 ...

  3. 2016.8.15上午纪中初中部NOIP普及组比赛

    2016.8.15上午纪中初中部NOIP普及组比赛 链接:https://jzoj.net/junior/#contest/home/1333 这次比赛不怎么好,因为这套题目我并不是很擅长. 可同学们 ...

  4. 背水一战 Windows 10 (15) - 动画: 缓动动画

    [源码下载] 背水一战 Windows 10 (15) - 动画: 缓动动画 作者:webabcd 介绍背水一战 Windows 10 之 动画 缓动动画 - easing 示例演示缓动(easing ...

  5. Linux Kernel 3.11.4/3.10.15/3.4.65/3.0.99

    Linux 今天又发布了4个更新版本,分别是: 3.11.4 2013-10-05 [tar.xz] [pgp] [patch] [view patch] [view inc] [cgit] [cha ...

  6. CVE-2015-1328 Ubuntu 12.04, 14.04, 14.10, 15.04 overlayfs Local Root

    catalog . 引言 . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch ...

  7. Oracle安全漏洞2016.10报告

    Oracle安全漏洞2016.10报告 http://www.cnvd.org.cn/webinfo/show/3950

  8. Codeforces Beta Round #10 D. LCIS

    题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...

  9. WTL汉化版2013.10.15

    汉化内容: 2013.10.15 版本:当前可下载Trunk最新版,wtl-code-467-trunk.zip 汉化内容: 1.应用向导的部分汉化,考虑到部分词汇的表述问题,只汉化无影响部分 2.资 ...

  10. [Mon Feb 10 15:21:06 2014] [notice] child pid 7101 exit signal File size limit exceeded (25)

    今天遇到的问题: LAMP的LOG里报如下错误. 然后IE和FIREFOX里显示连接被重置或是无法访问. 但自己建一个正常的PHP测试探针倒可以. 原来是PHP错误日志太多,无法写入LOG导致. [r ...

随机推荐

  1. js 日期格式化 函数

    function formatDate(date,format){ var paddNum = function(num){ num += ""; return num.repla ...

  2. OC类的本质及分类

    (一)类的本质 类对象(class object)与实例对象(instance object) 类本身也是一个对象,是class类型的对象,简称“类对象”. 在/usr/include/objc/ob ...

  3. redis数据类型:sets

    sets类型及操作: set是集合,它是string类型的无序集合.set是通过hash table实现的, 添加.删除和查找的复杂度都是O(1).对集合我们可以取并集.交集.差集. 通过这些操作我们 ...

  4. 快速进入pycharm图形界面

    解压后的pycharm相关文件的路径:/home/hadoop2/下载/pycharm-community-4.5.4 添加快速启动pycharm命令: (1)进入/usr/local/sbin这个目 ...

  5. 表单提交是ajax提交,PC提交没问题但是手机提交就会一直跳到error,并且也没状态码一直是0

    真是被自己蠢死了button标签他会自动提交刷新页面 <form id="baoming_from"> <p>请填写您的个人信息</p> < ...

  6. vb6加载时提示出错,窗体log文件中错误信息为:控件 XX 的类 MSComctlLib.ListView 不是一个已加载的控件类。

    解决办法:单击[工程] -- [部件] 添加此Microsoft Windows Common Controls-6.0 (SP6)部件,如果列表中没有,浏览到~\project\包\Support中 ...

  7. python2.7学习记录之四

    1.从raw_input()读取的内容永远以字符串的形式返回,把字符串和整数比较就不会得到期待的结果,必须先用int()把字符串转换为我们想要的整型 2.list增加元素 为 append() 3.d ...

  8. leetcode21

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  9. 简单Spring和mybatis整合配置文件

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  10. 几种访问其他域swf文件,或本地浏览器运行环境【安全沙箱】冲突解决方法

    声明: 几种方法都源自网络,我只负责汇总一下子,因为来自多方转载,也找不到初始出处了,需要的可以随意收藏,物尽其用,蛮好^_^ 对于类似的出错信息:SecurityError: Error #2148 ...