大佬们 求助bfs+剪枝 → 20分wa
  • 板块P1189 SEARCH
  • 楼主_weishiqi66_
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/3/16 13:52
  • 上次更新2023/10/23 21:25:38
查看原帖
大佬们 求助bfs+剪枝 → 20分wa
590571
_weishiqi66_楼主2023/3/16 13:52
#include<bits/stdc++.h>
#define map mapp
#define ll long long
using namespace std;
const int fx[]={0,-1,+1,0,0};
const int fy[]={0,0,0,-1,+1};

int n,m,s[1005];
bool pd[60][60][7];
char map[60][60];
struct uc{
    short x,y,step;
};
queue <uc> q;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>map[i][j];
            if(map[i][j]=='*'){
                q.push({i,j,1});
                map[i][j]='.';
            }
        }
    }
    int T;cin>>T;
    for(int i=1;i<=T;i++){
        string c; cin>>c;
        if(c=="NORTH") s[i]=1;
        if(c=="SOUTH") s[i]=2;
        if(c=="WEST")  s[i]=3;
        if(c=="EAST")  s[i]=4;
    }
    while(!q.empty()){
        uc tmp=q.front();q.pop();
        if(tmp.step==T+1){
            map[tmp.x][tmp.y]='*';
            continue;
        }
        int x=tmp.x+fx[s[tmp.step]];
        int y=tmp.y+fy[s[tmp.step]];
        while(!(x<1||y<1||x>n||y>m||map[x][y]=='X')){
            if(pd[x][y][tmp.step]==0){
                pd[x][y][tmp.step]=1;
                q.push({x,y,tmp.step+1});
            }
            x+=fx[s[tmp.step]];
            y+=fy[s[tmp.step]];
        }
    } 
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            cout<<map[i][j];
        cout<<endl;
    }
    return 0;
}
2023/3/16 13:52
加载中...