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文件,这往往是一件非常麻 ...
随机推荐
- Obj-C, library with ARC code and warning - Method possibly missing a [super dealloc] call?
1 down vote favorite I'm adding the MKStoreKit to my app and I'm getting a warning, Method possibly ...
- 带您了解Oracle层次查询
http://database.51cto.com/art/201010/231539.htm Oracle层次查询(connect by )是结构化查询中用到的,下面就为您介绍Oracle层次查询的 ...
- 【J2EE】十三个规范:愿天下苍生,人人如猿。
学习了J2ee后对java这个立足标准化的行为感到深深的佩服. 收买什么都不如收买人心,培养啥子都不如培养 习惯.没错,java就是在培养行业习惯,以一纸规范屹立不倒.毕竟技术什么的层出不穷,再新再前 ...
- CentOS 6.x安装多GCC版本号,cmake的安装与使用
操作系统:CentOS release 6.5 (Final) 当前gcc版本号:build=x86_64-redhat-linux Thread ...
- CVE-2014-4114 和 CVE-2014-3566
这两天关注安全的人员都会特别留意这两个新披露的漏洞:CVE-2014-4114 和 CVE-2014-3566.以下我们就针对这两个漏洞最一些简要说明. CVE-2014-4114------- ...
- centos Linux 常用命令汇总
CentOS 关闭防火墙 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后复原 开启: ...
- Androidclient验证Licence的原理
需求 限制App的使用,使App仅仅能在有许可的设备上执行. 分析及解决方式 原理 让App在每次执行的时候都连接server进行合法性验证--当然是一个非常成熟可靠的方案. 可是这样做的局限也是每次 ...
- aip接口中对url参数md5加密防篡改的原理
目前网上所有开放api的网站中,数据的调用都是采用同一种方式,即: http:www.xxx.com/aa=1&bb=2...,原后对这些参数按字典顺序排序后进行md5加密,将md5加密串与接 ...
- (转) Universal-Image-Loader使用大全(史上最屌)
转载自http://blog.csdn.net/zenjj11/article/details/38728481 项目介绍: Android上最让人头疼的莫过于从网络获取图片.显示.回收,不论什么一个 ...
- 1507: [NOI2003]Editor
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MB Submit: 3535 Solved: 1435 [Submit][St ...