WA on #2 #4 #10
  • 板块P1189 SEARCH
  • 楼主tqsw
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/5 15:48
  • 上次更新2023/11/2 15:29:52
查看原帖
WA on #2 #4 #10
711108
tqsw楼主2023/10/5 15:48
#include<iostream>
#include<string>
using namespace std;
int r,c,n,sx,sy;
char map[55][55];
bool visited[10005][55][55];
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
string str[1005];
int dire(char s){
    if(s=='N')return 2;
    if(s=='E')return 1;
    if(s=='W')return 0;
    if(s=='S')return 3;
}
void dfs(int x,int y,int s){
    if(visited[x][y][s])return;
    visited[x][y][s]=true;
    if(s==n+1){
        map[x][y]='*';
        return;
    }
    int x1=x,y1=y,a;
    a=dire(str[s][0]);
    x1+=dx[a],y1+=dy[a];
    while(x1<=r&&y1<=c&&x1>=1&&y1>=1&&map[x1][y1]!='X'){
        dfs(x1,y1,s+1);
        x1+=dx[a],y1+=dy[a];
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin>>r>>c;
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++){
            cin>>map[i][j];
            if(map[i][j]=='*')sx=i,sy=j;
        }
    map[sx][sy]='.';
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>str[i];
    dfs(sx,sy,1);
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++)
            cout<<map[i][j];
        cout<<endl;
    }
    return 0;
}
2023/10/5 15:48
加载中...