#include<iostream>
#include<algorithm>
using namespace std;
bool mp[100][100];
int dir,x,y;
void Move()
{
int tx=x,ty=y;
if(mp[x][y]==1)
{
if(dir==1){dir=4;y+=1;}
else if(dir==2){dir=3;y-=1;}
else if(dir==3){dir=1;x-=1;}
else if(dir==4){dir=2;x+=1;}
}
else
{
if(dir==1){dir=3;y-=1;}
else if(dir==2){dir=4;y+=1;}
else if(dir==3){dir=2;x+=1;}
else if(dir==4){dir=1;x-=1;}
}
mp[tx][ty]=mp[tx][ty]?0:1;
}
int main()
{
int M,N,step,i,j;
char c;
while(cin>>M>>N)
{
for(i=0;i<M;i++)for(j=0;j<N;j++)cin>>mp[i][j];
cin>>x>>y>>c>>step;
if(c=='U')dir=1;
else if(c=='D')dir=2;
else if(c=='L')dir=3;
else if(c=='R')dir=4;
while(step--)Move();
cout<<x<<' '<<y<<endl;
}
return 0;
}
兰顿蚂蚁
最新推荐文章于 2022-03-01 10:36:39 发布