CUC-SUMMER-10-A

A - Transformation: from A to B
CodeForces - 727A

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.

Example
Input
2 162
Output
YES
5
2 4 8 81 162
Input
4 42
Output
NO
Input
100 40021
Output
YES
5
100 200 2001 4002 40021


题意:你有一个起始数,你可以乘2或者乘10再加1这两种操作方式,问怎么操作能够变成目标数

解法:倒着推即可

代码:

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    double a,b,n,x,y,v,t,ans=999999999;
    scanf("%lf%lf%lf",&a,&b,&n);
    for(int i=0;i<n;i++){
        cin>>x>>y>>v;
        t=sqrt((x-a)*(x-a)+(y-b)*(y-b))/v;
        ans=min(ans,t);
    }
    printf("%.20lf",ans);
    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,155评论 0 23
  • 花开花落的样子(五) 第六章:人生常态 冷战。蚀烟与我们似乎像划清界限了一般,不再与我们一同吃饭,回...
    十三月_阿周阅读 333评论 0 0
  • 昨晚朋友圈被国足刷屏,有人发的振奋人心,有人发的搞笑有趣,而有的人发的则让我觉得心里有一个结,不吐不快。无...
    巨酷阅读 257评论 0 2
  • 在我的印象里小时候除了课本上的书几乎没有什么课外读物,小时候的成长环境毕竟是落后的,初中也在玩闹中度过了,插一句(...
    一朵太阳花shl阅读 159评论 0 0
  • 怎样才能够站在资本的背后?一直在不断的探索和追寻…… 资本的定义是金额的足够大,使用时限足够长,...
    心安是福铃儿响叮当阅读 196评论 0 0