为什么我的bfs不工作 [英] Why my bfs is not working

查看:115
本文介绍了为什么我的bfs不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在2d网格中应用bfs,但它显示的错误如下:



错误:变量或字段'bfs'声明无效

错误:'a'之前缺少模板参数



我尝试过:



iam trying to apply bfs in a 2d grid but it's showing errors like:

error:variable or field 'bfs' declared void
error:missing template argument before 'a'

What I have tried:

#include <iostream>
#include
using namespace std;


vector<int> g[100];
int vis[100][100];
int dis[100][100];
int grid[100][100];
int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

void bfs(pair a, pair b)
{
    pair x=a;
    memset(vis,0,sizeof vis);
    vis[x.first][x.second]=1;
    dis[x.first][x.second]=0;
    queue<pair>q;
    q.push(x);
    while(!q.empty())
    {
        pair v=q.front();
        for(int i=0;i<4;i++)
        {
            int c=v.first+fx[i];
            int d=v.second+fy[i];
            if(c>-1 and c<r and="" d="">-1 and d<c and="" mode="hold" />            {
                dis[c][d]=dis[v.first][v.second]+1;
                vis[c][d]=1;
                pair y=make_pair(c,d);
                q.push(y);
            }
        }
        q.pop();
    }
    cout<<dis[b.first][b.second]<<endl;

}


int main()
{

    // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(cin>>r>>c)
    {
        if(r!=0&&c!=0)
        {
            memset(grid,0,sizeof grid);
            int n;
            cin>>n;
            int row,number,col;
            for(int i=0; i<n;>            {
                cin>>row>>number;
                for(int j=0; j<number;>                {
                    cin>>col;
                    grid[row][b]=1;

                }
            }
            pair start,stop;
            cin>>start.first>>start.second;
            cin>>stop.first>>stop.second;
            bfs(start,stop);


        }
        else
            break;

    }


    //cout << "Hello world!" << endl;
    return 0;
}

推荐答案

对结构 [ ^ ]是一个模板,因此它需要声明项类型,如示例代码所示。
The pair Structure[^] is a template so it needs the item types to be declared, as shown in the example code.


这篇关于为什么我的bfs不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆