'commit'
This commit is contained in:
26
TangDou/XiTi/1382.cpp
Normal file
26
TangDou/XiTi/1382.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Node {
|
||||
int number; //值
|
||||
int cnt; //次数
|
||||
};
|
||||
|
||||
int main() {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
queue<Node> q;
|
||||
q.push({a, 0});
|
||||
while (q.size()) {
|
||||
auto t = q.front();
|
||||
q.pop();
|
||||
if (t.number == b) {
|
||||
cout << t.cnt << endl;
|
||||
break;
|
||||
}
|
||||
q.push({t.number + 1, t.cnt + 1});
|
||||
q.push({t.number * 2, t.cnt + 1});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user