文章

40

粉丝

512

获赞

13

访问

354.7k

头像
宽度优先搜索
Ang VIP
P1072
发布于2020年3月8日 17:33
阅读数 10.1k

#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

struct status{
    int n,t;
    status(int x,int y):n(x),t(y){}
};
bool visit[201];
int N,A,B;
int arr[201];
int BFS(int a,int b){
    queue<status> mq;
    mq.push(status(a,0));
    visit[a]=true;
    while(!mq.empty()){
        status current = mq.front();
        mq.pop();
        if(current.n==b){
            return current.t;
        }
        for(int i=0;i<2;i++){
            status next(current.n,current.t+1);
            if(i==0){
                next.n -= arr[next.n];
            }else{
            &nbs...

登录查看完整内容


登录后发布评论

1 条评论
admin SVIP
2020年3月9日 08:56

yes建议用代码插件,高亮语法显示,更容易阅读

赞(0)