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. xampp 搭建 web mac上

    1.安装 2.修改数据库密码,删除phpmyadmin  ,用navicat 控制数据库 3.修改/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhos ...

  2. 【简单学习shell】iptables命令实用

    构造设备离线iptables命令iptables -I INPUT -p all -s 10.71.115.159 -j DROP 断链iptables -I INPUT -p all -s 10.7 ...

  3. 文字编码转换器 V1.0 免费绿色版

    软件名称: 文字编码转换器 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / WinXP 软件大小: 920KB 图片预览: 软件简介: 文字编码转换器,能把普通文 ...

  4. php 好用的函数

    extract — 从数组中将变量导入到当前的符号表,数组的键将作为新的变量,数组的值将最为新变量的值

  5. JPA 系列教程10-双向一对一关联表

    双向一对一关联表的ddl语句 CREATE TABLE `t_person` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(255 ...

  6. Quartz任务调度器及与Spring的整合使用

    参考  点击打开链接

  7. 《JavaScript高级程序设计》读书笔记 ---语句

    do-while语句do-while 语句是一种后测试循环语句,即只有在循环体中的代码执行之后,才会测试出口条件.换句话说,在对条件表达式求值之前,循环体内的代码至少会被执行一次.以下是do-whil ...

  8. 8636 跳格子(dfs+记忆化搜索)

    8636 跳格子 该题有题解 时间限制:2457MS  内存限制:1000K提交次数:139 通过次数:46 题型: 编程题   语言: G++;GCC Description 地上有一个n*m 的数 ...

  9. PAT 天梯赛 L2-007 家庭房产

    建图+DFS 题目链接:https://www.patest.cn/contests/gplt/L2-007 题解 在热身赛的时候没有做出来,用的并查集的思想,但是敲残了,最后也没整出来.赛后听到别人 ...

  10. 【01-14】java ThreadLocal工具类

    自定义ThreadLocal package concurrent; import java.util.HashMap; import java.util.Map; /** * @author alo ...