RE(20pts前两个测试点)

P11228 [CSP-J 2024] 地图探险

wzj1105 @ 2024-11-01 22:21:59

Code(WA)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fst ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T,n,m,k,x,y,d;
struct node
{
    char c;
    bool tf;
};
signed main()
{
    fst;
    cin >> T;
    while(T--)
    {
       cin >> n >> m >> k >> x >> y >> d;
       node a[n][m];
       for(int i = 1;i <= n;i++)
       {
        for(int j = 1;j <= m;j++)
        {
            cin >> a[i][j].c;
            a[i][j].tf = false;
        }
       }
       int cnt = 0;
       for(int i = 0;i < k;i++)
       {
        if(d == 0)
        {
            int yi = y+1;
            if(yi <= m && a[x][yi].c == '.')
            {
               y = yi;
               if(a[x][y].tf == false)
               {
                cnt++;
                a[x][y].tf = true;
               }
            }else
            {
                d = (d + 1 ) % 4;
            }
        }else if(d==1)
        {
           int xi = x+1;
           if(xi <= n && a[xi][y].c == '.')
            {
               x = xi;
               if(a[x][y].tf == false)
               {
                cnt++;
                a[x][y].tf = true;
               }
            }else
            {
                d = (d + 1 ) % 4;
            }
        }else if(d == 2)
        {
            int yi = y-1;
            if(yi >= 1  && a[x][yi].c == '.')
            {
               y = yi;
               if(a[x][y].tf == false)
               {
                cnt++;
                a[x][y].tf = true;
               }
            }else
            {
                d = (d + 1 ) % 4;
            }
        }else if(d == 3)
        {
           int xi = x-1;
           if(xi >= 1 && a[xi][y].c == '.')
            {
               x = xi;
               if(a[x][y].tf == false)
               {
                cnt++;
                a[x][y].tf = true;
               }
            }else
            {
                d = (d + 1 ) % 4;
            }  
        }
       }
       cout << cnt+1 << endl;
    }
}

为什么会这样?


|