Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register
ACM ICPC 2018 World Finals

Re:第一次理解广搜 贴个代码

Posted by guiguai at 2017-12-03 20:43:18 on Problem 3278
In Reply To:第一次理解广搜 贴个代码 Posted by:154115081034 at 2016-04-03 11:50:52
```> #include<stdio.h>
> #include<string.h>
> #include<iostream>
> #include<queue>
> using namespace std;
>
> int step[100010];
> int vis[100010];
> queue <int> q;
>
> int BFS(int n, int k)
> {
>     int i;
>     q.push(n);
>     step[n]=0;
>     vis[n]=1;
>
>     while(!q.empty())
>     {
>         q.pop();
>         for(i=0; i<3; i++)
>         {
>
>             if(next<0 || next>100000) continue;
>             if(!vis[next])
>             {
>                 q.push(next);
>                 vis[next]=1;
>             }
>             if(next==k) return step[next];
>         }
>     }
> }
>
> int main()
> {
>     int n, k;
>
>     while(scanf("%d%d", &n, &k)!=EOF)
>     {
>         memset(step, 0, sizeof(step));
>         memset(vis, 0, sizeof(vis));
>
>         while(!q.empty()) q.pop();
>
>         if(n>=k)
>             printf("%d\n", n-k);
>         else
>             printf("%d\n", BFS(n, k));
>     }
> }
```

Followed by: