求助站外题
  • 板块灌水区
  • 楼主Mo_tang
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/3/13 10:03
  • 上次更新2023/10/28 06:42:42
查看原帖
求助站外题
474086
Mo_tang楼主2022/3/13 10:03

ybt 1253

题面

代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
	int di;
};
int n;
int k[100000]; 
int ans[100000];
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;
}

为什么但凡数据大一点就爆了!!!

2022/3/13 10:03
加载中...