#include<bits/stdc++.h>
#define M 50
using namespace std;
int n,m;
char maps[M + 5][M + 5];
int k;
int po[M * 20 + 5];
int fx[4][2] = {1,0,0,1,-1,0,0,-1};
int start_x,start_y;
char ans[M + 5][M + 5];
bool bk[M + 5][M + 5];
bool flag = true;
void dfs(int x,int y,int dep,int now,bool is_first){
if(dep > k){
// cout<<"stupid P1189 go away!!!!!"<<endl;
ans[x][y] = '*';
return ;
}
if(bk[x][y])return ;
for(int i = 1;i <= 2;i ++){
if(i == 1){
int nx = x + fx[now][0];
int ny = y + fx[now][1];
if(nx <= n && ny <= m && nx > 0 && ny > 0 && maps[nx][ny] != 'X'){
flag = false;
bk[nx][ny] = true;
dfs(nx,ny,dep,now,false);
//bk[nx][ny] = false;
}
}
if(i == 2 && flag != true){
int nx = x + fx[po[dep + 1]][0];
int ny = x + fx[po[dep + 1]][1];
if(nx <= n && ny <= m && nx > 0 && ny > 0 && maps[nx][ny] != 'X'){
bk[nx][ny] = true;
dfs(nx,ny,dep + 1,po[dep + 1],true);
//bk[nx][ny] = false;
}
}
}
}
int main(){
cin>>n>>m;
for(int i = 1;i <= n;i ++)
for(int j = 1;j <= m;j ++){
cin>>maps[i][j];
if(maps[i][j] == '*'){
start_x = i,start_y = j;
maps[i][j] = '.';
}
ans[i][j] = maps[i][j];
}
ans[start_x][start_y] = '.';
cin>>k;
for(int i = 1;i <= k;i ++){
string c;
cin>>c;
if(c == "NORTH")po[i] = 2;
if(c == "SOUTH")po[i] = 0;
if(c == "EAST")po[i] = 3;
if(c == "WEST")po[i] = 1;
}
dfs(start_x,start_y,1,po[1],true);
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= m;j ++)cout<<ans[i][j];
cout<<endl;
}
return 0;
}
太菜了,也太懒了,这种题目调不出来,也不想调