悬赏关注!!P1135 MLE, TLE, WA,大混合
  • 板块灌水区
  • 楼主hkl99
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/8/10 15:00
  • 上次更新2024/8/10 15:55:02
查看原帖
悬赏关注!!P1135 MLE, TLE, WA,大混合
770439
hkl99楼主2024/8/10 15:00

题目

不知道为什么又MLE一些,又TLE一些,又WA一些,又AC一些,悬赏一个关注!!!!!!!!

代码:

#include<bits/stdc++.h>
using namespace std;
int n,a,b,e[205];
bool c[205],flag=true;
struct node{
	int step,d;
};
queue<node>q;
void bfs(){
	node t;
	t.step=0;
	t.d=a;
	q.push(t);
	while(!q.empty()){
		t=q.front();
		q.pop();
		node tt;
		if(t.d-e[t.d]>0&&t.d-e[t.d]<=n&&c[t.d-e[t.d]]==true){
			tt.d=t.d-e[t.d];
			tt.step=t.step+1;
			q.push(tt);
			c[t.d-e[t.d]]==false;
			if(tt.d==b){
				printf("%d",tt.step);
				flag=false;
				return;
			}
		}
		if(t.d+e[t.d]>0&&t.d+e[t.d]<=n&&c[t.d+e[t.d]]==true){
			tt.d=t.d+e[t.d];
			tt.step=t.step+1;
			q.push(tt);
			c[t.d+e[t.d]]==false;
			if(tt.d==b){
				printf("%d",tt.step);
				flag=false;
				return;
			}
		}
	}
}
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		cin>>e[i];
	}
	memset(c,true,sizeof(c));
	bfs();
	if(flag){
		cout<<-1;
	}
	return 0;
}

求大佬调一调

2024/8/10 15:00
加载中...