站外深搜求调
  • 板块灌水区
  • 楼主zh_gyy
  • 当前回复11
  • 已保存回复11
  • 发布时间2023/11/5 11:01
  • 上次更新2023/11/5 12:18:30
查看原帖
站外深搜求调
999717
zh_gyy楼主2023/11/5 11:01

Link

#include<bits/stdc++.h>
using namespace std;
int m,n,t,res[2][4]={1,-1,0,0, 0,0,1,-1};
char a[105][105];
bool b[105][105],k;
void dfs(int h,int l,int c)
{
	if(a[h][l]=='E')
	{
		cout<<c<<'\n';
		k=true;
		return;
	}
	for(int i=0;i<4;++i)
	{
		int nh=h+res[0][i];
		int nl=l+res[1][i];
		if(k==1)
		  return;
		if(1>nh||nh>n||1>nl||nl>m)
		  continue;
		if(a[nh][nl]=='-'&&b[nh][nl]==false)
		{
			b[nh][nl]=true;
			dfs(nh,nl,c+1);
			b[nh][nl]=false;
		}
	}
}
int main()
{
	cin>>t;
	while(t--)
	{
		memset(b,false,sizeof(b));
		cin>>n>>m;
		for(int i=1;i<=n;++i)
		  for(int j=1;j<=m;++j)
			cin>>a[i][j];
		for(int i=1;i<=n;++i)
		  for(int j=1;j<=m;++j)
		    if(a[i][j]=='S')
		    {
		    	k=false;
		    	b[i][j]=true;
		    	dfs(i,j,0);
			}
	}
}

没有结果555……

2023/11/5 11:01
加载中...