#include using namespace std; const int N = 1010; int n, m; //结构体 struct Node { int num; int step; }; //队列中装的是结构体 queue q; void bfs() { //形成一个数对放入队列 q.push({n, 0}); //套路 while (q.size()) { auto x = q.front(); q.pop(); if (x.num == m) { printf("%d", x.step); break; } q.push({x.num + 1, x.step + 1}); q.push({x.num - 1, x.step + 1}); q.push({x.num * 2, x.step + 1}); } } int main() { cin >> n >> m; bfs(); return 0; }