求助站外题
  • 板块学术版
  • 楼主Mo_tang
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/3/19 14:26
  • 上次更新2023/10/28 06:13:20
查看原帖
求助站外题
474086
Mo_tang楼主2022/3/19 14:26

题面

#include<bits/stdc++.h>
using namespace std;
struct node{
	int di;
};
int n;
int k[10000]; 
int ans[10000];
bool jc(int aa){
	if(ans[aa]>0)return 0;
	if(aa<0||aa>100000)return 0;
	return 1;
}
int a,b;
void wwd(int x){
	queue<node>q;
	node ay;
	ay.di=x;
	q.push(ay);
	ans[x]=1;
	while(q.empty()==0){
		int as;
		as=q.front().di;
		int ae;
		ae=as-1;
		if(jc(ae)){
			ans[ae]=ans[as]+1;
			node by;
			by.di=ae;
			q.push(by);
		}
		if(ae==b){
			cout<<ans[ae]-1;
			return ;
		}
		ae=as+1;
		if(jc(ae)){
			ans[ae]=ans[as]+1;
			node by;
			by.di=ae;
			q.push(by);
		}
		if(ae==b){
			cout<<ans[ae]-1;
			return ;
		}
		ae=as*2;
		if(jc(ae)){
			ans[ae]=ans[as]+1;
			node by;
			by.di=ae;
			q.push(by);
		}
		if(ae==b){
			cout<<ans[ae]-1;
			return ;
		}
		q.pop();
	}
}
int main(){

	cin>>a>>b;
	if(a==b){
		cout<<0;
		return 0;
	}
	wwd(a);
	return 0;
}

真的不会了

完全运行错误???? 自己测试样例没毛病a

2022/3/19 14:26
加载中...