RE求助
查看原帖
RE求助
1027669
BlueSky楼主2023/11/27 19:51

本地运行第一个数据结果正确,但是re,只过了一个点。不知哪里出错

#include<iostream>
#include<queue>
using namespace std;

int A, B, N, depth = 0;
int ki[210]; //存储楼梯上下层----方向;
bool visited[210]={0};//存储是否访问---探索是否访问;
int countall[210] = { 0 };	//路径记录器;
queue <int> q;
int main()
{
	cin >> N >> A >> B;
	for (int i = 1; i <= N; i++)
	{
		cin >> ki[i];
	}
	if (A == B) {
		cout << 0;
		return 0;
	}
	visited[A] = true;
	q.push(A);
	while (!q.empty())
	{
		int t = q.front();
		q.pop();
		int tempa = t + ki[t], tempb = t - ki[t];
		if (!visited[tempa] && tempa <= N && tempa > 0) {
			visited[tempa] = true;
			countall[tempa] = countall[t] + 1;
			q.push(tempa);
		}
		if (!visited[tempb] && tempb > 0 && tempb <= N) {
			q.push(tempb);
			visited[tempb] = true;
			countall[tempb] = countall[t] + 1;
		}
		if (tempa == B || tempb == B) {
			depth = countall[t] + 1;
			break;
		}
	}
	if (depth > 0)cout << depth;
	else cout << -1;
	return 1;

}


2023/11/27 19:51
加载中...