hdu 1072 广搜

时间:2021-06-11 19:33:53

路径是可以重复走的,但是如果再一次走过时间重置点是没有意义的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;

;
int mp[N][N];
struct Node {
    int x, y, step, time;
};
int m, n;
][] = {,, ,, -,, ,-};

int bfs(int x, int y) {
    queue<Node> que;
    Node start;
    start.x = x; start.y = y; start.step = ; start.time = ;
    que.push(start);
    while(!que.empty()) {
        Node cur = que.front();
        que.pop();
        )
            continue;
        ; i<; i++) {
            ];
            ];
            Node nextstep;
            nextstep.x = tx; nextstep.y = ty;
            nextstep.step = cur.step+; nextstep.time = cur.time-;
             || ty< || tx>=m || ty>=n) {
                continue;
            }
            ) continue;
            ) {
                )
                    ;
                else
                    continue;
            }
            ) {
                ){
                    nextstep.time = ;
                    mp[tx][ty] = ;         //只能走一次,走多了就没有意义了
                } else {
                    continue;
                }
            }
            que.push(nextstep);
        }
    }
    ;
}
int main()
{
    int t;
    cin>>t;
    while(t--) {
        cin>>m>>n;
        int x, y;
        ; i<m; i++) {
            ; j<n; j++) {
                cin>>mp[i][j];
                ) {
                    x = i; y = j;
                }
            }
        }
        cout<<bfs(x, y)<<endl;
    }
    ;
}