80WA求调

P11228 [CSP-J 2024] 地图探险

shenqing_QAQ @ 2024-11-04 21:50:05

玄2关

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int T,n,m,k;
int sx,sy,sd,ans;
char a[N][N];
bool vis[N][N][4];
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct node
{
    int x,y,d,step;
};
queue<node> q;
void bfs()
{
    while(!q.empty()) q.pop();
    vis[sx][sy][sd]=1;
    q.push((node){sx,sy,sd,0});
    while(!q.empty())
    {
        node now=q.front();
        q.pop();
        if(now.step==k) return;
        int xx=now.x+dx[now.d],yy=now.y+dy[now.d];
        if(vis[xx][yy][now.d]) return;
        if(a[xx][yy]!='x'&&xx>0&&xx<=n&&yy>0&&yy<=m)
        {
            ans+=!(vis[xx][yy][0]||vis[xx][yy][1]||vis[xx][yy][2]||vis[xx][yy][3]);
            vis[xx][yy][now.d]=1;
            q.push((node){xx,yy,now.d,now.step+1});
        }
        else
        {
            xx=now.x,yy=now.y;
            int dd=(now.d+1)%4;
            if(vis[xx][yy][dd]) return;
            vis[xx][yy][dd]=1;
            q.push((node){xx,yy,dd,now.step+1});
        }
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>k>>sx>>sy>>sd;
        ans=1;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                cin>>a[i][j],vis[i][j][0]=vis[i][j][1]=vis[i][j][2]=vis[i][j][3]=0;
        bfs();
        cout<<ans<<endl;
    }
    return 0;
}

by FarmerDrone @ 2024-11-04 22:36:59

@shenqing_QAQ a[xx][yy]!='x'&&xx>0&&xx<=n&&yy>0&&yy<=m会不会越界啊感觉越界好像没什么后果但是可以改一下试试?


by shenqing_QAQ @ 2024-11-04 22:39:26

@FarmerDrone 感谢,但是改了也一样


|