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文件,这往往是一件非常麻 ...
随机推荐
- java验证身份证号码是否有效源代码 wn25的头像 wn25 23 2015-01-04 20:09 6 基本信息 Java × 1 浏览
原文:http://www.open-open.com/code/view/1420373343171 1.描述 用java语言判断身份证号码是否有效,地区码.出身年月.校验码等验证算法 2.源代码 ...
- 使用Reveal 调试iOS应用程序
Itty Bitty Apps发布了一款实用工具——Reveal,它能够在运行时调试和修改iOS应用程序.Reveal能连接到应用程序,并允许开发者编辑各种用户界面参数,这反过来会立即反应在程序的UI ...
- call lua function from c and called back to c
Just a simple example: --The c file: #include <stdio.h> #include "lua.h" #include & ...
- c++ struct与class的差别
从语法上,在C++中(仅仅讨论C++中).class和struct做类型定义时仅仅有两点差别: (一)默认继承权限. 假设不明白指定,来自class的继承依照private继承处理.来自struct的 ...
- Visual Studio VS2013模块对于SAFESEH 映像是不安全的 怎么办
打开该项目的"属性页"对话框,会出现如下界面打开该项目的"属性页"对话框,会出现如下界面 然后单击"链接器"--"命令行&qu ...
- three.js 源代码凝视(十五)Math/Plane.js
商域无疆 (http://blog.csdn.net/omni360/) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:商域无疆 - 本博客专注于 敏捷开发 ...
- css 滤镜之AlphaImageLoader
CreateTime--2017年12月25日17:05:37 Author:Marydon ie滤镜特效之AlphaImageLoader 作用: 用于设置背景图片特效样式 使用条件: IE8及 ...
- POJ - 1062 昂贵的聘礼(最短路Dijkstra)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u SubmitStatus Descr ...
- YII RBAC基于角色的访问控制
基于角色的访问控制( Role-Based Access Control ),是一种简单的而又强大的集中访问控制.基于Yii Framework 的 authManager 组件实现了分等级的 RBA ...
- CPU维修技术
中央处理单元(Central Process Unit)简称CPU,是电脑的核心部件,负责处理和运算电脑内部所有数据.因其在电脑中的地位相当重要,所以一旦发生故障就会造成很严重的后果. [技术66]开 ...