广搜实现a+b
2026-03-30 21:31:26
发布于:浙江
25阅读
0回复
0点赞
广搜实现a+b (核弹炸蚊子)
#include<iostream>
#include<queue>
using namespace std;
struct node{
int pos, step;
};
int add(int x, int y) {
queue<node> q;
q.push({x, 0});
while(q.size()) {
node l = q.front();
q.pop();
if(l.pos == -y) {
return l.step;
}
l.pos < -y?
q.push({l.pos + 1, l.step + 1}) :
q.push({l.pos - 1, l.step + 1});
}
return 0;
}
int main() {
int a, b;
cin >> a >> b;
int sum = add(a,b);
cout << sum << endl;
return 0;
}
纯整活
这里空空如也


有帮助,赞一个