挺简单的一道广搜题,只要用判断时间是偶数还是奇数就可以判断楼梯的方位,但是我这傻逼居然写了那么久啊那么久,我果然秀逗了,,,,
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 30
int map[MAXN][MAXN],n,m;
bool vis[MAXN][MAXN];
struct tt
{
int x,y,step;
};
queue<tt>q;
int xx[]={,,,-};
int yy[]={,-,,};
int bfs(int x,int y)
{
while(!q.empty())
q.pop();
memset(vis,false,sizeof(vis));
tt front,rear,temp;
front.x=x;front.y=y;front.step=;
q.push(front);
vis[x][y]=true;
while(!q.empty())
{
temp=q.front();
q.pop();
if(map[temp.x][temp.y]=='T')
return temp.step;
for(int i=;i<;i++)
{
rear.x=temp.x+xx[i];
rear.y=temp.y+yy[i];
rear.step=temp.step+;
if(rear.x>=&&rear.x<n&&rear.y>=&&rear.y<m&&map[rear.x][rear.y]!='*'&&vis[rear.x][rear.y]==false)
{
if(map[rear.x][rear.y]=='.'||map[rear.x][rear.y]=='T')
{
q.push(rear);
vis[rear.x][rear.y]=true;
}
if(xx[i]==)
{
if(map[rear.x][rear.y]=='-')
{
if(rear.y+yy[i]>=&&rear.y+yy[i]<m&&(map[rear.x][rear.y+yy[i]]=='.'||map[rear.x][rear.y+yy[i]]=='T')&&vis[rear.x][rear.y+yy[i]]==false)
{ if(rear.step%==)
rear.y=rear.y-yy[i];
else
rear.y=rear.y+yy[i],vis[rear.x][rear.y]=true;
q.push(rear);
}
}
else if(map[rear.x][rear.y]=='|')
{
if(rear.y+yy[i]>=&&rear.y+yy[i]<m&&(map[rear.x][rear.y+yy[i]]=='.'||map[rear.x][rear.y+yy[i]]=='T')&&vis[rear.x][rear.y+yy[i]]==false)
{
if(rear.step%)
rear.y=rear.y-yy[i];
else
rear.y=rear.y+yy[i],vis[rear.x][rear.y]=true;
q.push(rear);
}
}
}
if(yy[i]==)
{
if(map[rear.x][rear.y]=='|')
{
if(rear.x+xx[i]>=&&rear.x+xx[i]<n&&(map[rear.x+xx[i]][rear.y]=='.'||map[rear.x+xx[i]][rear.y]=='T')&&vis[rear.x+xx[i]][rear.y]==false)
{ if(rear.step%==)
rear.x=rear.x-xx[i];
else
rear.x=rear.x+xx[i],vis[rear.x][rear.y]=true;
q.push(rear);
}
}
else if(map[rear.x][rear.y]=='-')
{
if(rear.x+xx[i]>=&&rear.x+xx[i]<n&&(map[rear.x+xx[i]][rear.y]=='.'||map[rear.x+xx[i]][rear.y]=='T')&&vis[rear.x+xx[i]][rear.y]==false)
{
if(rear.step%)
rear.x=rear.x-xx[i];
else
rear.x=rear.x+xx[i],vis[rear.x][rear.y]=true;
q.push(rear);
}
}
}
}
}
}
return ;
} int main()
{
int i,j,sx,sy,ans;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<n;i++)
{
getchar();
for(j=;j<m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
sx=i;sy=j;
}
}
}
ans=bfs(sx,sy);
printf("%d\n",ans);
}
return ;
} /*
1 3
S|T
1 3
S-T
20 20
S.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.|
|.|.|.|.|.|.|.|.|.|.
.|.|.|.|.|.|.|.|.|.T
5 5
**..T
**.*.
..|..
.*.*.
S....
*/