【wikioi】1026逃跑的拉尔夫

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值