为什么读不了方向?
  • 板块P1189 SEARCH
  • 楼主福明o7
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/2/3 17:01
  • 上次更新2023/10/28 09:46:02
查看原帖
为什么读不了方向?
566903
福明o7楼主2022/2/3 17:01
#include<bits/stdc++.h>
using namespace std;
int	_m,n;
char c[55][55];
bool m[55][55],v[1005][55][55];
int to[1005];
int pos[4][2]={1,0,0,1,-1,0,0,-1};
int bx,by;
void dfs(int d,int x,int y){
	if(v[d][x][y]) return;
	v[d][x][y]=1;
	if(d==0) return;
	while(1){
		x+=pos[to[d]][0];
		y+=pos[to[d]][1];
		if(!m[x][y]) break;
		dfs(d-1,x,y);
	}
}
int main(){
	scanf("%d %d",&_m,&n);
	for(int i=1;i<=_m;i++){
		for(int j=1;j<=n;j++){
			scanf("%c",&c[i][j]);
			if(c[i][j]=='.') m[i][j]=1;
			if(c[i][j]=='*'){
				m[i][j]=1;
				bx=i;
				by=j;
			}
		}
	}
	int k;
	string s;
	cin>>k;
	for(int i=k;i>0;i--){
		cin>>s;
		if(s[0]=='S') to[i]=0;
		if(s[0]=='E') to[i]=1;
		if(s[0]=='N') to[i]=2;
		if(s[0]=='W') to[i]=3;
	}
	dfs(k,bx,by);
	for(int i=1;i<=_m;i++){
		for(int j=1;j<=n;j++){
			if(v[0][i][j]==1) printf("*");
			else if(m[i][j]) printf(".");
			else printf("X");
		}
		puts(" ");
	}
	return 0;
}

人傻了

2022/2/3 17:01
加载中...