思路:
模拟
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int row,line;
cin>>row;
cin>>line;
vector<vector<int>>mat(row,vector<int>(line,0));
int num;
for(int i=0;i<row;i++)
{
for(int j=0;j<line;j++)
{
cin>>num;
mat[i][j]=num;
}
}
int begin_row,begin_line;
cin>>begin_row;
cin>>begin_line;
char begin_dic;
getchar();
cin>>begin_dic;
int step;
cin>>step;
while(step--)
{
if(mat[begin_row][begin_line]==0)
{
if(begin_dic=='U')
{
begin_dic='L';
mat[begin_row][begin_line]=1;
begin_line--;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='R')
{
begin_dic='U';
mat[begin_row][begin_line]=1;
begin_row--;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='D')
{
begin_dic='R';
mat[begin_row][begin_line]=1;
begin_line++;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='L')
{
begin_dic='D';
mat[begin_row][begin_line]=1;
begin_row++;
//cout<<begin_row<<" "<<begin_line<<endl;
}
}
else
{
if(begin_dic=='U')
{
begin_dic='R';
mat[begin_row][begin_line]=0;
begin_line++;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='R')
{
begin_dic='D';
mat[begin_row][begin_line]=0;
begin_row++;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='D')
{
begin_dic='L';
mat[begin_row][begin_line]=0;
begin_line--;
//cout<<begin_row<<" "<<begin_line<<endl;
}
else if(begin_dic=='L')
{
begin_dic='U';
mat[begin_row][begin_line]=0;
begin_row--;
//cout<<begin_row<<" "<<begin_line<<endl;
}
}
}
cout<<begin_row<<" "<<begin_line<<endl;
}
//for(auto n:mat)
//{
// for(auto n1:n)
// {
// cout<<n1<<" ";
// }
// cout<<endl;
// }
// cout<<"开始坐标"<<begin_row<<" "<<begin_line<<" 方向:"<<begin_dic<<" 步数:"<<step;