超简单搜索题求调
查看原帖
超简单搜索题求调
1020186
zhouxianzhuo楼主2024/8/21 15:27

题解用的是 priority_queue,本人用的是 queue,同学用 queue 也过了

调半天调不出来,求大佬帮调

#include<bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,tx,ty,e[210][210],me[210][210];
int ttx[5]={0,0,0,1,-1},tty[5]={0,1,-1,0,0};
char a[210][210];
queue<int> x,y,z;
bool bfs(){
	x.push(sx);
	y.push(sy);
	z.push(e[sx][sy]);
	me[sx][sy]=e[sx][sy];	//记录最大能量 
	while(!z.empty())
	{
		if(z.front()>=1)
		{
			for(int i=1;i<=4;i++)
			{
				int xx=x.front()+ttx[i],yy=y.front()+tty[i],zz=z.front()-1;
				if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[xx][yy]!='#'&&zz>me[xx][yy])
				{
					if(xx==tx&&yy==ty)return true;
					x.push(xx);
					y.push(yy);
					zz=max(zz,e[xx][yy]);
					z.push(zz);
					me[xx][yy]=zz;
				}
			}
		}
		x.pop();
		y.pop();
		z.pop();
	}
	return false;
}
int main(){
	memset(me,-1,sizeof(me));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=='S')
			{
				sx=i;
				sy=j;
			}
			if(a[i][j]='T')
			{
				tx=i;
				ty=j;
			}
		}
	}
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		e[x][y]=max(e[x][y],z);		//记录能获得最大能量的药 
	}
	if(bfs())printf("Yes");
	else printf("No");
	return 0;
}
2024/8/21 15:27
加载中...