头像

欢迎来到我的博客

分享题解与总结

混境之地

混境之地

屏幕截图 2026-03-17 170336

屏幕截图 2026-03-17 170447

屏幕截图 2026-03-17 170527

屏幕截图 2026-03-17 170559

思路:

  1. BFS

  2. 结点携带“剩余可使用喷气背包次数”的信息struct node{int x,y,step,rem;//remain-times};

  3. 判断是否可走:

    高度单调不增√

    或者当前结点还可以使用喷气背包,且使用后高度够得着√

    其余×

图解

屏幕截图 2026-03-17 220239

代码

int n,m,k,sx,sy,ex,ey;
int e[N][N],nxt[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
bool book[N][N];
struct node{
	int x,y,step,rem;//remain-times
};

void bfs()
{
	node head;
	queue<node> q;
	int tx,ty;
	q.push({sx,sy,0,1});
	book[sx][sy]=true;
	if(sx==ex&&sy==ey){ cout<<"Yes"<<"\n";return ;}
	
	while(!q.empty())
	{
		head=q.front(); q.pop();
		for(int i=0;i<4;++i)
		{
			tx=head.x+nxt[i][0];
			ty=head.y+nxt[i][1];
			if(tx<1||ty<1||tx>n||ty>m) continue;
			if(book[tx][ty]==false)//没遍历过
			{
				if(e[tx][ty]<=e[head.x][head.y])//高度下降
				{
					book[tx][ty]=true;
					q.push({tx,ty,head.step+1,head.rem});
					if(tx==ex&&ty==ey){ cout<<"Yes"<<"\n";return ;}
				}
				else
				{
					if(head.rem>0&&e[head.x][head.y]+k>=e[tx][ty])//有剩余次数 且够得着 
					{
						book[tx][ty]=true;
						q.push({tx,ty,head.step+1,head.rem-1});
						if(tx==ex&&ty==ey){ cout<<"Yes"<<"\n";return ;}
					}
				}
			}
		}
	}
	cout<<"No"<<"\n";
}

int main()
{
	cin>>n>>m>>k;
	cin>>sx>>sy>>ex>>ey;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			cin>>e[i][j];
		}
	}
	bfs();
	return 0;
}
posted @ 2026-03-17 22:09  king_steph1209  阅读(3)  评论(0)    收藏  举报