```cpp
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int INF=999999999;
struct node
{
int x;
int y;
int mian;
int step;
};
queue<node>q;
int n,m;
int tttt[51][51];
bool book[61][61][4];
int stx,sty,edx,edy;
char MIAN[10];
int t[61][61];
int tx;
int ty;
int tmian;
int ans=INF;
int bfs()
{
memset(book,false,sizeof(book));
int is;
if(MIAN[0]=='W')
{
book[stx][sty][1]=1;
is=1;
}
if(MIAN[0]=='N')
{
book[stx][sty][2]=1;
is=2;
}
if(MIAN[0]=='E')
{
book[stx][sty][3]=1;
is=3;
}
if(MIAN[0]=='S')
{
book[stx][sty][4]=1;
is=4;
}
node tt;
tt.x=stx;
tt.y=sty;
tt.step=0;
tt.mian=is;
q.push(tt);
node now;
while(!q.empty())
{
node hehe=q.front();
printf("%d %d %d %d\n",hehe.x,hehe.y,hehe.mian,hehe.step);
if(hehe.x==edx&&hehe.y==edy)
{
ans=hehe.step;
break;
}
for(int k=1;k<=5;k++)
{
if(k==1)
{
if(hehe.mian==1)
{
tx=hehe.x;
ty=hehe.y-1;
}
if(hehe.mian==2)
{
tx=hehe.x-1;
ty=hehe.y;
}
if(hehe.mian==3)
{
tx=hehe.x;
ty=hehe.y+1;
}
if(hehe.mian==4)
{
tx=hehe.x+1;
ty=hehe.y;
}
if(tx<=0||ty<=0||tx>=n||ty>=m)
{
continue;
}
if(book[tx][ty][hehe.mian])
{
continue;
}
if(t[tx][ty]==1)
{
continue;
}
now.x=tx;
now.y=ty;
now.mian=hehe.mian;
now.step=hehe.step+1;
book[tx][ty][hehe.mian]=true;
q.push(now);
}
if(k==2)
{
if(hehe.mian==1)
{
tx=hehe.x;
ty=hehe.y-2;
}
if(hehe.mian==2)
{
tx=hehe.x-2;
ty=hehe.y;
}
if(hehe.mian==3)
{
tx=hehe.x;
ty=hehe.y+2;
}
if(hehe.mian==4)
{
tx=hehe.x+2;
ty=hehe.y;
}
if(tx<=0||ty<=0||tx>=n||ty>=m)
{
continue;
}
if(book[tx][ty][hehe.mian])
{
continue;
}
if(t[tx][ty]==1)
{
continue;
}
now.x=tx;
now.y=ty;
now.mian=hehe.mian;
now.step=hehe.step+1;
book[tx][ty][hehe.mian]=true;
q.push(now);
}
if(k==3)
{
if(hehe.mian==1)
{
tx=hehe.x;
ty=hehe.y-3;
}
if(hehe.mian==2)
{
tx=hehe.x-3;
ty=hehe.y;
}
if(hehe.mian==3)
{
tx=hehe.x;
ty=hehe.y+3;
}
if(hehe.mian==4)
{
tx=hehe.x+3;
ty=hehe.y;
}
if(tx<=0||ty<=0||tx>=n||ty>=m)
{
continue;
}
if(book[tx][ty][hehe.mian])
{
continue;
}
if(t[tx][ty]==1)
{
continue;
}
now.x=tx;
now.y=ty;
now.mian=hehe.mian;
now.step=hehe.step+1;
book[tx][ty][hehe.mian]=true;
q.push(now);
}
if(k==4)
{
tx=hehe.x;
ty=hehe.y;
tmian=(hehe.mian-1);
if(tmian==0)
{
tmian=4;
}
if(book[tx][ty][tmian])
{
continue;
}
now.x=tx;
now.y=ty;
now.mian=tmian;
now.step=hehe.step+1;
book[tx][ty][tmian]=true;
q.push(now);
}
if(k==5)
{
tx=hehe.x;
ty=hehe.y;
tmian=(hehe.mian+1);
if(tmian==5)
{
tmian=1;
}
if(book[tx][ty][tmian])
{
continue;
}
now.x=tx;
now.y=ty;
now.mian=tmian;
now.step=hehe.step+1;
book[tx][ty][tmian]=true;
q.push(now);
}
}
q.pop();
}
return ans!=INF?ans:-1;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&tttt[i][j]);
}
}
scanf("%d%d%d%d%s",&stx,&sty,&edx,&edy,MIAN);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(tttt[i][j])
{
t[i][j]=1;
t[i-1][j-1]=1;
t[i-1][j]=1;
t[i][j-1]=1;
}
}
}
/*printf("---------\n");
for(int i=0;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
printf("%d ",t[i][j]);
}
printf("\n");
}*/
printf("%d",bfs());
return 0;
}
```
by Brandon鹏 @ 2018-10-27 08:55:47
# 太真实了
by Brandon鹏 @ 2018-10-27 08:56:28
dalao
by HenryJoestar @ 2018-10-27 08:59:55
@[std_20201916](/space/show?uid=147187) 大佬看得出问题吗???
by Brandon鹏 @ 2018-10-27 09:02:45
应该是机器人可能穿墙
by 汤汤tongtongTOT @ 2018-10-27 09:09:09
@[汤汤tongtongTOT](/space/show?uid=101742) ???能说详细一点吗
by Brandon鹏 @ 2018-10-27 09:20:25
你有给右和下设边界吗
by Jackcy @ 2018-10-27 09:30:56
@[Brandon鹏](/space/show?uid=86154)
by Jackcy @ 2018-10-27 09:32:33
@[十分地弱鸡](/space/show?uid=81150)
if(tx>=n||ty>=m)
{
continue;
}
这句话应该是对的吧,机器人不能走到0和n,m的边界上
by Brandon鹏 @ 2018-10-27 09:33:05
我再看一下
by Jackcy @ 2018-10-27 09:34:56