样例都过不了 code
#include<iostream>
#include<queue>
using namespace std;
int R,C;
bool map[60][60];
char f[60][60];
// r l d u
int pyx[5]={0,0,1,-1},
pyy[5]={1,-1,0,0};
struct node{
int x,y;
};
queue <node> q;
void bfs(int t)
{
while(!q.empty())
{
node s=q.front();
q.pop();
for(int k=1;;k++)
{
int xx=s.x+k*pyx[t],yy=s.y+k*pyy[t];
if(xx<1||yy<1||xx>R||yy>C||map[xx][yy]) break;
map[xx][yy]=1;
node p;
p.x=xx;p.y=yy;
f[xx][yy]='*';
q.push(p);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>R>>C;
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
char ch;
cin>>ch;
if(ch=='X') map[i][j]=1,f[i][j]=ch;
else if(ch=='*') map[i][j]=1,q.push(node{i,j}),f[i][j]='.';
else f[i][j]=ch;
}
}
int l;
cin>>l;
for(int i=1;i<=l;i++)
{
string k;
cin>>k;
int t;
if(k=="NORTH") t=3;
else if(k=="WEST") t=1;
else if(k=="SOUTH") t=2;
else t=0;
bfs(t);
}
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
{
cout<<f[i][j];
}
cout<<endl;
}
return 0;
}