全WA求助
查看原帖
全WA求助
523553
cxzhyf楼主2023/6/2 19:07

样例过了,结果爆0......

#include<bits/stdc++.h>
using namespace std;
struct zzntn{
	int x,s;
}st,ed,ne;
queue <zzntn> q;
int t,b[100006],fx[2]={1,-1};
void bfs()
{
	int i;
	while(!q.empty()){
		for(i=0;i<3;i++){
			if(i==2) ne.x=q.front().x*2;
			else ne.x=q.front().x+fx[i];
			ne.s=q.front().s+1;
			if(ne.x>=0&&ne.x<=100000&&b[ne.x]==0){
				if(ne.x==ed.x){
					cout<<ne.s;
					return;
				}
				q.push(ne);
				b[ne.x]=1;
			}
		}
		q.pop();	
	}
}
int main()
{
	cin>>t;
	while(t--){
		cin>>st.x>>ed.x;
		if(st.x==ed.x){
			cout<<0;
			return 0;
		}
		q.push(st);
		b[st.x]=1;
		bfs();
	}
	return 0;
}

怎么有这么水的样例(悲)

2023/6/2 19:07
加载中...