CE求助
  • 板块灌水区
  • 楼主ming2023
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/1/18 00:40
  • 上次更新2024/1/18 12:20:16
查看原帖
CE求助
1103464
ming2023楼主2024/1/18 00:40

如题 这条语句在本地可以通过编译,但放到洛谷IDE/评测机会CE掉 求助

floorBFS.push( pair {target,nextStep} );

完整代码 题目P1135

#include<bits/stdc++.h>
using namespace std;

const int N=1e5+50;

int n,a,b;
int floorChange[N];
bool isVis[N];

queue<pair<int,int> > floorBFS;
int main()
{
	cin>>n>>a>>b;
	
	for (int i=1;i<=n;++i) cin>>floorChange[i];
	
	floorBFS.push({a,0});
	isVis[a]=1;
	while(!floorBFS.empty())
	{
		int floorNow=floorBFS.front().first;
		int totalMove=floorBFS.front().second;
		floorBFS.pop();
		
		if (floorNow==b)
		{
			cout<<totalMove;
			return 0;
		}
		int target,nextStep;
		target=floorNow+floorChange[floorNow];
		nextStep=totalMove+1;
		if (target>=1 && target<=n && isVis[target]==0)
		{
			isVis[target]=1;
			floorBFS.push(pair{target,nextStep});
		}
		target=floorNow-floorChange[floorNow];
		if (target>=1 && target<=n && isVis[target]==0)
		{
			isVis[target]=1;
			floorBFS.push(pair{target,nextStep});
		}

	}
	cout<<"-1";
	return 0;
}
2024/1/18 00:40
加载中...