20分求助(RE)

P11228 [CSP-J 2024] 地图探险

Jasper2024 @ 2024-10-27 14:43:47

#include <iostream>
using namespace std;
int main()
{
    int i,t;
    cin>>t;
    for(i=0;i<t;i++)
    {
        int n,m,k,x,y,d,x1,y1,sum=1;
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        char a[n][m];
        for(int j=1;j<=n;j++)
            for(int q=1;q<=m;q++)
                cin>>a[j][q];
        for(int j=0;j<k;j++)
        {
            if(d==0)
            {
                x1=x;
                y1=y+1;
            }
            else if(d==1)
            {
                x1=x+1;
                y1=y;
            }
            else if(d==2)
            {
                x1=x;
                y1=y-1;
            }
            else if(d==3)
            {
                x1=x-1;
                y1=y;
            }
            if(x1<1||x1>n||y1<1||y1>m||a[x1][y1]=='x') 
            {
                d=d+1;
                d=d%4;
            }
            else if(x1>=1&&x1<=n&&y1>=1&&y1<=m&&a[x1][y1]!='x')
            {
                x=x1;
                y=y1;
                if(a[x1][y1]=='.')
                    sum++;
                a[x1][y1]=',';
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

by LANDER_TT @ 2024-10-27 21:24:43

@Jasper2024 你数组越界了

char a[n][m] -> char a[1005][1005]

|