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. C# 语言规范_版本5.0 (第1章 介绍)

    1. 介绍 C#(读作“See Sharp”)是一种简洁.现代.面向对象且类型安全的编程语言.C# 起源于 C 语言家族,因此,对于 C.C++ 和 Java 程序员,可以很快熟悉这种新的语言.C# ...

  2. Excel教程(13) - 统计函数

    AVEDEV 用途:返回一组数据与其平均值的绝对偏差的平均值,该 函数可以评测数据(例如学生的某科考试成绩)的离散度. 语法:AVEDEV(number1,number2,...) 参数:Number ...

  3. erlang ets表

    一.表遍历 通过ets:first/1获取表的第一个关键字,表中下一个关键字用ets:next/2得到,直到ets:next/2返回'$end_of_table' 当多几个进程并发访问ets表时,可以 ...

  4. C++设计模式-参考资料

    设计模式实例讲解: http://www.cnblogs.com/jiese/tag/ http://www.cnblogs.com/wanggary/category/294620.html 设计模 ...

  5. linux 内核协议栈收报流程(二)Netfilter全貌

    ip层分片整理 int ip_local_deliver(struct sk_buff *skb){ /* * Reassemble IP fragments. */ if (ip_is_fragme ...

  6. Ztree手风琴效果(第三版)

    第一版:点击一级目录展开,再点击时不能收回 第二版:点击一级目录展开,再点击时可以收回 第三版:优化样式,修复主菜单下的子菜单下级无子节点时点击无反应问题(js报错) <%@ page lang ...

  7. 《Windows驱动开发技术详解》之驱动程序调用驱动程序——通过设备指针调用其他驱动程序

    本节介绍“手动”构造各个IRP,然后将IRP传递到相应驱动程序的派遣函数里. 获得设备指针 每个内核中的句柄都会和一个内核对象的指针联系起来.ZwCreateFile内核函数可以通过设备名打开设备句柄 ...

  8. hdu_2838_Cow Sorting(树状数组求逆序对)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 题意:给你一串数,让你排序,只能交换相邻的数,每次交换花费交换的两个树的和,问最小交换的价值 题 ...

  9. 开始工作----微信通过get检查当前网站---是否可用

    01开发者--基本配置--url服务器地址---填写好--需要开通微信接口的域名 http://www.cctv.com/xxx.php文件 xxx.php文件 01参考wx_sample.php 0 ...

  10. mvc 母版页、用户自定义控件

    母版页(Master) 1.母版页是与Controller无关的,母版页只是一个View文件,而没有任何Controller与之相对应. 2.其实在ASP.NET MVC中View的aspx与母版页并 ...