10分求条!!(壶关)

P11228 [CSP-J 2024] 地图探险

lzacode @ 2024-10-26 21:30:17

rt

我的代码:

#include <bits/stdc++.h>
using namespace std;

char a[1001][1001];
int vis[1001][1001];

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n, m, k;
        cin >> n >> m >> k;
        int x, y, d;
        cin >> x >> y >> d;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cin >> a[i][j];
            }
        }
        vis[x][y]=1;
        for (int i = 1; i <= k; i++)
        {
            if (d==0)
            {
                if (y+1<=m&&a[x][y+1]!='x')
                {
                    y++;
                    vis[x][y]++;
                } 
                else d=(d+1)%4;
            }
            else if (d==1)
            {
                if (x+1<=n&&a[x+1][y]!='x')
                {
                    x++;
                    vis[x][y]++;
                } 
                else d=(d+1)%4;
            }
            else if (d==2)
            {
                if (y-1>=1&&a[x][y-1]!='x')
                {
                    y--;
                    vis[x][y]++;
                } 
                else d=(d+1)%4; 
            }
            else if (d==3)
            {
                if (x-1>=1&&a[x-1][y]!='x')
                {
                    x--;
                    vis[x][y]++;
                }
                else d=(d+1)%4; 
            }
        }
        int ans=0; 
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (vis[i][j]!=0)
                {
                    ans++;  
                } 
            }
        }
        cout << ans << endl;
    } 
    return 0;
}

样例过了,为什么不对呢QAQ

求调,thx


by Bigtanks10 @ 2024-10-26 21:33:21

好像没有吧vis初始化


by zhiqin__ @ 2024-10-26 21:34:53

@lzacode vis[]在每组数据开始的时候都要初始化


by Bigtanks10 @ 2024-10-26 21:36:22


|