我吐了,当时还想自己手写结束,结果现在自己写个bfs直接出结果hhh
要命,当初手写那答案,还是错的 TAT
答案是14, 不是17!!!!!不是!!!!
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
int main(void){
int a = 2021;
queue<PII> q;
q.push({a,0});
while(q.size()){
auto t = q.front();
q.pop();
int num = t.first, step = t.second;
if(num==1){
printf("%d",step);
break;
}
if(num<=a){
if(num%2==0) q.push({num/2,step+1});
q.push({num+1,step+1});
q.push({num-1,step+1});
}
}
return 0;
}