#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<cstdlib>
#include<map>
using namespace std;
struct bign {
int x,y,time;
};
int dx[5]={0,-1,0,1,0}, dy[5]={0,0,-1,0,1};
int n,m,b[100][100],step[2000],x,y,a[100][100],p,now[100][100][1001];
char s,ts[1000];
queue<bign>d;
void bfs(){
int direction,tempx,tempy;bign t,tmp;
while(!d.empty()){
t=d.front();
direction=step[++t.time];
tempx=t.x;tempy=t.y;
for(;;){
tempx+=dx[direction];
tempy+=dy[direction];
if(tempx>0 && tempx<=n && tempy>0 && tempy<=m && a[tempx][tempy]){
b[tempx][tempy]=t.time;
tmp.x=tempx;tmp.y=tempy;tmp.time=t.time;
if(tmp.time!=p && !now[tempx][tempy][t.time])
{d.push(tmp);now[tempx][tempy][t.time]=1;}
}
else break;
}
d.pop();
}
}
const int INF=2147483647;
int main(){
cin>>n>>m;
bign temp;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>s;
if(s=='X')a[i][j]=0;else a[i][j]=1;
if(s=='*'){temp.x=i;temp.y=j;temp.time=0;
}
}
d.push(temp);
cin>>p;
for(int i=1;i<=p;i++){
scanf("%s",ts);
if(ts[0]=='N') step[i]=1;
if(ts[0]=='W') step[i]=2;
if(ts[0]=='S') step[i]=3;
if(ts[0]=='E') step[i]=4;
}
bfs();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]==p) cout<<'*';else
cout<<((a[i][j]==1)?'.':'X');
}
cout<<endl;
}
return 0;
}
【wikioi】1026逃跑的拉尔夫
最新推荐文章于 2017-01-22 22:26:39 发布