40pts求助

P11228 [CSP-J 2024] 地图探险

jiuyehuaer @ 2024-10-31 21:38:21

#include<bits/stdc++.h>
using namespace std;
int n, m, d, sx, sy, k;
char ma[10001][10001];
int cnt = 1, t, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
    cin >> t;
    while (t--) {
        cnt = 1;
        cin >> n >> m >> k;
        cin >> sx >> sy >> d;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++)cin >> ma[i][j];
        }
        while (k) {
            int nx = sx + dx[d];
            int ny = sy + dy[d];
            k--;
            if (nx <= 0 || ny <= 0 || nx > n || ny > m || ma[nx][ny] == 'x') {
                d=(d+1)%4;
            } else {
                sx=nx;
                sy=ny;
                cnt++;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

by jiuyehuaer @ 2024-11-01 18:58:32

@sunpeilun 全局变量不是会自动初始化吗


by sunpeilun @ 2024-11-01 19:47:40

@jiuyehuaer 不谢


by jiuyehuaer @ 2024-11-10 16:56:14

@sunpeilun 全局变量不是会自动初始化吗


by sunpeilun @ 2024-11-10 17:52:18

@jiuyehuaer 有t组数据,每一组都要初始化


上一页 |