问一下怎么跳出这个奇葩的while
查看原帖
问一下怎么跳出这个奇葩的while
255540
Her_Lingxiao楼主2020/6/15 13:10
#include <cstdio>
#include <queue>
using namespace std;
struct ele
{
	int floor;
	int step; 
};
queue<ele> q;
int main()
{
	int a, b, n;
	int k[202];
	int DaBiao[202] = {0};
	scanf("%d %d %d", &a, &b, &n);
	ele A;
	A.floor = a;
	A.step = 0;
	for(int i = 1; i <= n; i++)
		scanf("%d", &k[i]);
	q.push(A);
	DaBiao[a] = 1;
	while(q.size())
	{
		if(q.front().floor == b)
			break;
		
		if(!DaBiao[q.front().floor])
		{
			ele zancun_1;
			ele zancun_2;
			zancun_1.step = q.front().step + 1;
			zancun_2.step = q.front().step + 1;
			
			if(q.front().floor + k[q.front().floor + 1] >= 0)
			{
				zancun_1.floor = q.front().floor + k[q.front().floor + 1];
				DaBiao[q.front().floor] = 1;
				q.push(zancun_1);
			}
			if(q.front().floor - k[q.front().step + 1] >= 0)
			{
				zancun_2.floor = q.front().floor + k[q.front().floor + 1];
				DaBiao[q.front().floor] = 1;
				q.push(zancun_2);
			}
			else
				DaBiao[q.front().floor] = 0;
			
			q.pop();
		}
	}
	printf("%d", q.back().step);
	return 0;
	
}
2020/6/15 13:10
加载中...