文章

82

粉丝

343

获赞

27

访问

661.3k

头像
BFS 注意判断n和k的大小
P1678 中南大学2017年机试题
发布于2021年3月20日 19:14
阅读数 7.4k

#include <iostream>
#include <algorithm>
#include <stack>
#include <string.h>
#include <stdio.h>
#include <queue>
using namespace std;

int vis[200005];
struct node {
    int step;
    int x;
    node(int a,int b){
        x=a;
        step=b;
    }
};
int bfs(int s,int e){
    queue <node> q;
    int ans=1e9;
    q.push(node{s,0});
    vis[s]=1;
    while(!q.empty()){
        node tt=q.front();
        q.pop();
        if(tt.x==e){
           ans=min(ans,tt.step);
        }
        else{
            int xx=tt.x+1;
            if(xx<2*e&&xx>0&&!vis[xx]){
      ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发