A. Transformation: from A to B
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputIf 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.
Examplesinput2 162outputYES
5
2 4 8 81 162input4 42outputNOinput100 40021outputYES
5
100 200 2001 4002 40021
题意:
有两种变换方式:
(1)x*10+1
(2)x*2
问a能否经过两种变换转换成b
如果b是奇数,则必是由(1)方式转换而来,若为偶数则必是(2)转换而来。
附AC代码:
#include<bits/stdc++.h>
using namespace std; int c[]; int main(){
int a,b;
cin>>a>>b;
int ans=;
c[]=b;
int flag=;
while(a<b){
if((b-)%==){
b=(b-)/;
c[ans++]=b;
}
else if(b%==){
b/=;
c[ans++]=b;
}
else{
flag=;
break;
}
}
if(flag==){
cout<<"NO"<<endl;
}
else if(a==b){
cout<<"YES"<<endl;
cout<<ans<<endl;
for(int i=ans-;i>=;i--){
cout<<c[i]<<" ";
}
}
else{
cout<<"NO"<<endl;
}
return ;
}
A. Transformation: from A to B的更多相关文章
- (七)Transformation和action详解-Java&Python版Spark
Transformation和action详解 视频教程: 1.优酷 2.YouTube 什么是算子 算子是RDD中定义的函数,可以对RDD中的数据进行转换和操作. 算子分类: 具体: 1.Value ...
- 线性分式变换(linear fractional transformation)
线性分式变换(linear fractional transformation)的名称来源于其定义的形式:(ax+b)/(cx+d),其中分子分母是线性的,然后最外层是一个分式形式,所以叫做这个名字, ...
- OLE DB Command transformation 用法
OLE DB Command transformation component 能够引用参数,逐行调用sqlcommand,This transformation is typically used ...
- OpenCASCADE General Transformation
OpenCASCADE General Transformation eryar@163.com Abstract. OpenCASCADE provides a general transforma ...
- Informatica Lookup Transformation组件的Connect 与Unconnected类型用法
Informatica Lookup Transformation组件的Connect 与Unconnected类型用法及区别:下面是通一个Lookup在不同Mapping中的使用: 1. Conne ...
- Data Transformation / Learning with Counts
机器学习中离散特征的处理方法 Updated: August 25, 2016 Learning with counts is an efficient way to create a compact ...
- VS非web项目使用Transformation配置文件
Web项目中的Transformation使用起来非常方便,特别是本地与服务器情况不一致时调试下以及webdeploy的配合使用. 步骤: 1. 在项目中新建App.Debug.Config及App. ...
- SAP SLT (Landscape Transformation) 企业定制培训
No. Item Remark 1 SAP SLT概述 SAP Landscape Transformation Overview 2 SAP SLT 安装与配置<1> for abap ...
- Scalaz(55)- scalaz-stream: fs2-基础介绍,fs2 stream transformation
fs2是scalaz-stream的最新版本,沿用了scalaz-stream被动式(pull model)数据流原理但采用了全新的实现方法.fs2比较scalaz-stream而言具备了:更精简的基 ...
- 使用Web.Config Transformation配置灵活的配置文件
发布Asp.net程序的时候,开发环境和发布环境的Web.Config往往不同,比如connectionstring等.如果常常有发布的需求,就需要常常修改web.config文件,这往往是一件非常麻 ...
随机推荐
- systemtap初体验
https://phpor.net/blog/post/3471 写在前面: systemtap依赖的debuginfo可以从这里(http://debuginfo.centos.org/6/x86_ ...
- vueSSR渲染原理
优点:利于搜索引擎,解决白屏问题,因为正常情况下在index.html文件中只有一个简单的标签,没有内容,不利于爬虫搜索 场景:交互少,数据多,例如新闻,博客,论坛类等 原理:相当于服务端前面加了一层 ...
- [CSS3] Define Form Element States with CSS Form Pseudo Classes
Using just semantic CSS Pseudo-Classes you can help define important states for form elements that e ...
- 设计模式C++实现——工厂方法模式
模式定义: 工厂方法模式定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个. 工厂方法让类把实例化推迟到子类. 模式结构: Creator是一个类,它实现了全部操纵产品的方法,但不实现工厂方法 ...
- antd 如何让 Row 中的 Col 自动换行?
1.解决方案 在需要换行处,设置一个空的 Col // 空白(特殊情况处理) const empty = ( <Col md={6} sm={24}></Col> ); .
- Linux下的ELF可执行文件的格式解析 (转)
LInux命令只是和Kernel一起被编译进操作系统的存在于FS的ELF格式二进制文件,或者权限足够的脚本,或者一个软链 ELF(Executable and Linking Format)是一种对象 ...
- LeetCode——Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- 【转载】C#扫盲之:静态成员、静态方法、静态类、实例成员及区别
文章目录 1.静态成员.实例成员 2.静态类 3.类的静态成员和非静态成员区别 --------------------------------------分割线------------------- ...
- 【Unity 3D 游戏开发】Unity3D 入门 - 工作区域介绍 与 入门演示样例
一. 工作区域具体解释 1. Scence视图 (场景设计面板) scence视图简单介绍 : 展示创建的游戏对象, 能够对全部的游戏对象进行 移动, 操作 和 放置; -- 演示样例 : 创建一个球 ...
- 作为iOS程序员,最核心的60%能力有哪些?
作为iOS程序员,最核心的60%能力有哪些? 一个合格的iOS程序员需要掌握多少核心技能?你和专业的开发工程师的差距有多大?你现在的水平能开发一个功能完整性能高效的iOS APP吗?一起来看看下面 ...