zoukankan      html  css  js  c++  java
  • poj 3278 Catch That Cow (BFS)

    题意:

        牛逃跑了,主人用最短的时间追到牛(在直线上)

        很裸的bfs ,郁闷啊忘了判断重复了,RE ,WA !

       

    #include<stdio.h>
    #define N 100005
    int n,k;
    int stack[N],vis[N];
    int main()
    {

    scanf("%d%d",&n,&k);
    int di=0,top=1,first=0,last=1;
    int sum=0;stack[0]=n,vis[n]=1;
    while(di!=top)
    {
    last--;
    int num=stack[di++];
    if(num!=k)
    {

    if(num+1<=100000&&!vis[num+1])
    {
    vis[num+1]=1;
    first++;
    stack[top++]=num+1;
    top%=N;
    }
    if(2*num<=100000&&!vis[num*2])
    {
    vis[num*2]=1;
    stack[top++]=num*2;
    top%=N;
    first++;
    }
    if(num>0&&!vis[num-1])
    {
    vis[num-1]=1;
    stack[top++]=num-1;
    top%=N;
    first++;
    }

    }
    else
    {
    break;
    }
    if(last==0)
    {
    sum++;

    last=first;first=0;
    }
    di%=N;
    }
    printf("%d\n",sum);
    return 0;
    }



    Just a little, maybe change the world
  • 相关阅读:
    P2572 [SCOI2010]序列操作
    python学习笔记2
    嗯,python
    ETROBOT——审题
    条件编译
    第三章单片机简介
    模拟输入输出
    arduino库函数1
    arduino相关文献阅读
    Arduino的小灯亮起来~~~
  • 原文地址:https://www.cnblogs.com/skyming/p/2386046.html
Copyright © 2011-2022 走看看