Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A
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.
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.
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.
2 162
YES
5
2 4 8 81 162
4 42
NO
100 40021
YES
5
100 200 2001 4002 40021
题意:就是从a变成b(*2或者的*10+1),可以就输出具体变化
解法:额。。搜索一下嘛
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;
int a[];
long long n,m;
int flag;
int cnt;
void dfs(int cnt,long long x){ a[cnt]=x;
if(x>m){
return;
}
if(x==m&&flag==){
flag=;
cout<<"YES"<<endl;
cout<<cnt<<endl;
for(int i=;i<=cnt;i++){
cout<<a[i]<<" ";
}
}
dfs(cnt+,x*+);
dfs(cnt+,x*);
}
int main(){
cin>>n>>m;
dfs(,n);
if(flag==){
cout<<"NO"<<endl;
}
return ;
}
Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) A的更多相关文章
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) D
The organizers of a programming contest have decided to present t-shirts to participants. There are ...
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) C
This is an interactive problem. You should use flush operation after each printed line. For example, ...
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) B
Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C
Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B
Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A
Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL
D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines
E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)
http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...
随机推荐
- 【bzoj2588】Count on a tree 主席树
这题给人开了个新思路. 原本构造一个序列的主席树,是这个位置用上个位置的信息来省空间,树上的主席树是继承父亲的信息来省空间. 此题若带修改怎么办? 若对某个点的权值做修改,则这个点的子树都会受影响,想 ...
- [noi2002]荒岛野人 拓展欧几里得
克里特岛以野人群居而著称.岛上有排列成环行的M个山洞.这些山洞顺时针编号为1,2,…,M.岛上住着N个野人,一开始依次住在山洞C1,C2,…,CN中,以后每年,第i个野人会沿顺时针向前走Pi个洞住下来 ...
- VS2010关于调用ffmpeg借口出错
win7 下开发视频服务器,用到ffmpeg,debug版本运行正常,切换到release时,出现"0x00905a4d 处未处理的异常: 0xC0000005: 读取位置 0x00905a ...
- 常用的PHP类库,PHP开发者必备【转】
PHP开发者常用的PHP类库和组件 PDF 生成器 FPDF - 这量一个可以让你生成PDF的纯PHP类库. Excel 相关 你的站点需要生成Excel?没有问题,下面这两个类库可以让你轻松做到这一 ...
- C语言中文件操作
用两个指针变量来操作字符串. 多维数组在做函数参数的时候,会退化成为一个指针变量,变成一个指向一维数组的数组指针,注意,是一个指针变量. 一维数组在当作函数参数传递的时候,会退化成为一个对应类型的指针 ...
- 中缀表达式std
#include<cstdio>#include<cstdlib>#include<string>#include<cstring>using name ...
- mysql跨表更新示例
一.在同一个表中冗余存储记录之间的关系(组织机构树),查询时需要根据冗余字段进行关联查询 例如,下面的示例,用户表中有个字段friend标记其朋友关系,要求找出id=2及他的朋友(父节点) mysql ...
- zabbix snmp、jmx配置使用
SNMP: snmp是很古老的监控,我萌几乎可以在所有设备上看到它的身影 [root@linux-node1 ~]# yum install net-snmp net-snmp-libs net-sn ...
- bzoj4804
莫比乌斯反演 我不会推线性筛 留坑
- Windows服务卸载服务窗口仍显示的问题
关于Windows服务通过命令卸载后, 打开服务窗口,服务还有显示,只是状态改为了禁用,运行停止.那么我们怎么解决呢, 不要心慌,打开你的任务管理器,查看服务所用的exe程序是否还在运行,若有的话,便 ...