10分求助!!!

P11228 [CSP-J 2024] 地图探险

Sutong123 @ 2024-10-28 21:32:02

#include <bits/stdc++.h>
using namespace std;
int T;
int main (){
    scanf ("%d", &T);
    for (int i = 1; i <= T; i++) {
        int n, m, k;
        scanf ("%d%d%d", &n, &m, &k);
        int x0, y0, d0;
        scanf ("%d%d%d", &x0, &y0, &d0);
        int x = x0, y = y0, d = d0;
        const int N = n + 10;
        const int M = m + 10;
        char map0[N][M];
        int steps = 1;
        for (int j = 1; j <= n; j++)
            for (int z = 0; z <= m; z++)
                scanf ("%c", &map0[j][z]);
        for (int j = 1; j <= k; j++) {
            if (d == 0) {
                y += 1;
                if (map0[x][y] == 'x' || y > n) {
                    y--;
                    d = (d + 1) % 4;
                }
                else
                    steps++;
            }
            if (d == 1) {
                x += 1;
                if (map0[x][y] == 'x' || x > m) {
                    x--;
                    d = (d + 1) % 4;
                }
                else
                    steps++;
            }
            if (d == 2) {
                y -= 1;
                if (map0[x][y] == 'x' || y < 0) {
                    y++;
                    d = (d + 1) % 4;
                }
                else
                    steps++;
            }
            if (d == 3) {
                x -= 1;
                if (map0[x][y] == 'x' || x < 0) {
                    x++;
                    d = (d + 1) % 4;
                }
                else
                    steps++;
            }
        }
        printf ("%d\n", steps);
    }
    return 0;
}

帮忙看一下哪里错误,谢谢。 (只有第四点对的,五和六RE了)


by ly_magician @ 2024-10-31 20:47:26

我也是十分,终于找到跟我分一样的了


|