第十四届蓝桥杯大赛软件赛国赛C/C++ 大学 B 组 AB路线

第十四届蓝桥杯大赛软件赛国赛C/C++ 大学 B 组 AB路线_第1张图片
//bfs 1000100010不会超时

#include
using namespace std;
#define int long long 
const int n=1e3+11;
int a,b,c,h[n][n][12],k[4][2]={0,1,0,-1,1,0,-1,0}; 
char t[n][n];
struct s 
{
	int x,y,z,w;
};
signed main()
{
	ios::sync_with_stdio(false);
	  cin.tie(0),cout.tie(0);
	cin>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			cin>>t[i][j];
		}
	}
	queueq;
	q.push({1,1,1,0});
	h[1][1][1]=1;
	while(!q.empty())
	{
		s m=q.front();
		q.pop();
		if(m.x==a&&m.y==b)
		{
			cout<=1&&xx<=a&&yy>=1&&yy<=b)
			{
				if(m.z==c)
				{
					if(h[xx][yy][1]==0&&t[xx][yy]=='B'&&t[m.x][m.y]=='A')
					{
						h[xx][yy][1]=1;
						q.push({xx,yy,1,m.w+1});
					}
					if(h[xx][yy][1]==0&&t[xx][yy]=='A'&&t[m.x][m.y]=='B')
					{
						h[xx][yy][1]=1;
						q.push({xx,yy,1,m.w+1});
					}
				}
				else
				{
					if(t[xx][yy]==t[m.x][m.y]&&h[xx][yy][m.z+1]==0)
					{
						h[xx][yy][m.z+1]=1;
						q.push({xx,yy,m.z+1,m.w+1});
					}
				}
			}
		}
	}
	cout<<"-1"<

你可能感兴趣的:(蓝桥杯,c语言,c++)