10分TWT
查看原帖
10分TWT
799098
chengzihan620楼主2023/8/22 10:35
#include<bits/stdc++.h> 
using namespace std;
struct oe{
	int x,cost;
};
//bool s[10001];
int d[]={-1,1,0};
int main(){
	int n;
	cin>>n;
	queue<oe> q;
	q.push({1,0});
	while(q.size()){
		oe tmp=q.front();
		q.pop();
		tmp.cost++;
		for(int i=0;i<3;i++){
			tmp.x=tmp.x+(d[i]?d[i]:tmp.x);
			if(tmp.x==n){
				cout<<tmp.cost;
				return 0;
			}
			//if(!s[tmp.x])
				q.push(tmp);
		}
	}
	return 0;
}
2023/8/22 10:35
加载中...