文章

16

粉丝

134

获赞

0

访问

3.4k

头像
迷宫 题解:AC
P1563 天津大学/南开大学2019年机试题
发布于2024年4月9日 23:24
阅读数 171

//迷宫问题求起点到终点的最短路径(自己写的代码)

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

struct node {
    int x;
    int y;
    int step;
};

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
    int h, w;
    while(scanf("%d%d", &h, &w) != EOF) {
        if(h == 0 && w == 0)
            break;

        int startx, starty;
        queue<node> r;
        int vis[105][105] = {0}; // 初始化 vis 数组
        char a[105][105];

        for(int i = 1; i <= h; i++) {
            cin >> (a[i] + 1);
            for(int j = 1; j <= w; j++) {
                if(a[i][j] == 'S') {
          &n...

登录查看完整内容


登录后发布评论

2 条评论
snake
2024年4月10日 09:22

这个代码多组输入的时候会出问题

需要把前面用过的重新初始化,比如vis数组、队列这些,否则会影响下一次计算结果

赞(0)

为欢几何 : 回复 snake: 谢谢,已改好

2024年4月10日 17:06