50分求调

P11228 [CSP-J 2024] 地图探险

chujinxuan @ 2024-11-17 14:34:47

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

int T, f[5][3] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
bool vis[1010][1010];
char Map[1010][1010];

int main()
{
    cin >> T;
    while (T--)
    {
        int n, m, k, x, y, d, sum = 1;
        cin >> n >> m >> k >> x >> y >> d;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) cin >> Map[i][j];
        for (int i = 0; i < k; i++)
        {
            int xx = x + f[d][0], yy = y + f[d][1];
            if (Map[xx][yy] == 'x' || xx < 1 || xx > n || yy < 1 || yy > m) d = (d + 1) % 4;
            else
            {
                if (!vis[xx][yy]) sum++, vis[xx][yy] = true;
                x = xx, y = yy;
            }
        }
        cout << sum << endl;
        memset(vis, false, sizeof(vis));
    }
    return 0;
}

by Azure_Space @ 2024-11-17 22:19:26

@[chujinxuan](luogu://user/1364839 你没把起点的vis赋值为1


by pythonc__________ @ 2024-12-06 21:53:09

你还好点,我这题是 0pts求调


|