else
{
q.step=temp.step+1;
que.push(q);
}
}
}
}
else if(map[xx][yy]=='-')
{
if(temp.step%2==0)
{
if(can(xx+dir[i][0],yy+dir[i][1]))
{
q.x=xx+dir[i][0];
q.y=yy+dir[i][1];
vis[q.x][q.y]=1;
if((i==1||i==0))
{
q.step=temp.step+2;
que.push(q);
}
else
{
q.step=temp.step+1;
que.push(q);
}
}
}
else
{
if(can(xx+dir[i][0],yy+dir[i][1]))
{
q.x=xx+dir[i][0];
q.y=yy+dir[i][1];
vis[q.x][q.y]=1;
if((i==1||i==0))
{
q.step=temp.step+1;
que.push(q);
}
else
{
q.step=temp.step+2;
que.push(q);
}
}
}
}
else
{
vis[xx][yy]=1;
/*注意楼梯用过了1遍之后还可以再用 因为用来横着走之后还可以竖着走 所以不标记楼梯是否走过*/
q.x=xx;
q.y=yy;
q.step=temp.step+1;
que.push(q);
}
}
}
}
int main()
{
int i,j;
while(scanf("%d %d",&n,&m)!=EOF)
{
for(i=0;i
scanf("%s",map[i]);
for(j=0;j
if(map[i][j]=='S') {sx=i;sy=j;}
else if(map[i][j]=='T') {ex=i;ey=j;}
}
}
int ans=0; ans=BFS();
printf("%d\n",ans);
}
return 0;
}
#include
#include
#include
using namespace std;
char map[30][30];
int vis[30][30];
int sx,sy,ex,ey,n,m;
struct haha
{
int x;
int y;
int step;
friend bool operator<(haha a,haha b)
{
return a.step>b.step;
}
}q,temp;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
bool can(int xx,int yy)
{
if(xx>=0&&xx
}
int BFS()
{
int i;
priority_queue
q.x=sx;
q.y=sy;
q.step=0;
que.push(q);
memset(vis,0,sizeof(vis));
vis[sx][sy]=1;
while(!que.empty())
{
temp=que.top();
que.pop();
if(temp.x==ex&&temp.y==ey) return temp.step;
for(i=0;i<4;i++)
{
int xx;int yy;
xx=temp.x+dir[i][0];
yy=temp.y+dir[i][1];
if(can(xx,yy))
{
if(map[xx][yy]=='|')//如果初始状