求调代码
查看原帖
求调代码
356117
落木之樱meow楼主2024/5/10 19:29

这个题死的莫名其妙的(求调

#include <stdio.h>
#define N 10
char mp[N + 2][N + 2];
bool vis[N + 2][N + 2][N + 2][N + 2][4][4];
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

inline void turn(int &x) {x = (x + 1) % 4;}

int main() {
    int fx, fy, cx, cy, df = 0, dc = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            mp[i][j] = getchar();
            if (mp[i][j] == 'F') {
                mp[i][j] = '.';
                fx = i, fy = j;
            }
            if (mp[i][j] == 'C') {
                mp[i][j] = '.';
                cx = i, cy = j;
            }
        }
        getchar();
    }
    for (int i = 0; i <= 11; i++) {
        mp[0][i] = '*';
        mp[11][i] = '*';
        mp[i][0] = '*';
        mp[i][11] = '*';
    }
    int cnt = 0;
    int tx, ty;
    do {
        cnt ++;
        vis[cx][cy][fx][fy][dc][df] = true;
        tx = cx + dir[dc][0], ty = cy + dir[dc][1];
        if (mp[tx][ty] == '*') {
            dc = (dc + 1) % 4;
        } else {
            cx = tx, cy = ty;
        }
        tx = fx + dir[df][0], ty = fy + dir[df][1];
        if (mp[tx][ty] == '*') {
            df = (df + 1) % 4;
        } else {
            fx = tx, fy = ty;
        }
        if (fx == cx && fy == cy) {
            printf("%d", cnt);
            return 0;
        }
    } while (!vis[cx][cy][fx][fy][dc][df]);
    printf("0");
    return 0;
}
2024/5/10 19:29
加载中...