#include<iostream>
#define MAX 100001
int john,cow;
int queue[MAX];
int vis[MAX];
int ans; void bfs()
{
int tail,head;
tail=head=;
int start=john;
queue[tail++]=start;
vis[start]=;
while(head!=tail)
{
int cur,next;
cur=queue[head++];
if(cur==cow)
{
ans=vis[cur]-;
return;
}
next=cur;
next=cur+;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
} next=cur-;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
}
next=*cur;
if(next>=&&next<MAX&&vis[next]==)
{
vis[next]=vis[cur]+;
queue[tail++]=next;
}
}
} int main()
{
//freopen("input.txt","r",stdin);
std::cin>>john>>cow;
for(int i=;i<MAX;i++)
vis[i]=;
bfs();
std::cout<<ans;
return ;
}

poj3278的更多相关文章

  1. poj3278 Catch That Cow

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 73973   Accepted: 23308 ...

  2. ACM/ICPC 之 BFS-广搜+队列入门-抓牛(POJ3278)

    这一题是练习广度优先搜索很好的例题,在很多广搜教学中经常用到,放在这里供学习搜索算法的孩纸们看看= = 题目大意:一维数轴上,农夫在N点,牛在K点,假定牛不会移动,农夫要找到这头牛只能够进行以下三种移 ...

  3. POJ3278——Catch That Cow(BFS)

    Catch That Cow DescriptionFarmer John has been informed of the location of a fugitive cow and wants ...

  4. 暑假集训(1)第二弹 -----Catch the cow(Poj3278)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  5. POJ-3278(BFS)

    题目:                                                                                                 ...

  6. poj3278 BFS入门

    M - 搜索 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit I ...

  7. POJ3278 Catch That Cow(BFS)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  8. poj3278(bfs)

    题目链接:http://poj.org/problem?id=3278 分析:广搜,每次三种情况枚举一下,太水不多说了. #include <cstdio> #include <cs ...

  9. 超超超简单的bfs——POJ-3278

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 89836   Accepted: 28175 ...

随机推荐

  1. easyui textbox 获取焦点

    function Admin_ListAdd() { $('#ListInfo').css({ display: "inherit" }); $("#Department ...

  2. Centos7.4别名设置提高工作效率

    一.打开 .bashrc文件 1.位置:~(cd ~)目录下 2.cat .bashrc 原文件内容如下: # .bashrc # User specific aliases and function ...

  3. nginx实现限速

    项目中有一个需求,需要限制每个容器的网速,避免某些容器占用太多资源,导致其他容器无法使用,但是docker对于网速的限制支持的有点弱,由于容器中的所有进程和APP的交互都是通过nginx的,所以就想到 ...

  4. 代理_正向代理_反向代理_nginx_转

    转自:Nginx 相关介绍(Nginx是什么?能干嘛?)   蔷薇Nina 关于代理 说到代理,首先我们要明确一个概念,所谓代理就是一个代表.一个渠道: 此时就设计到两个角色,一个是被代理角色,一个是 ...

  5. zookeeper入门及使用(二)- 状态查看

    查看服务的角色,看Mode字段,有follower及leader [root@c7bit1 bin]# echo stat | nc 127.0.0.1 2181 Zookeeper version: ...

  6. 针对json的查询--alibaba的开源项目jsonq

    项目地址: https://github.com/alibaba/jsonq 示例json { , , "test": "Hello, world!", &qu ...

  7. 【C语言】 重拾

    [C语言] 因为以前学过C语言,只不过太长时间不用,已经忘得差不多了… 所以这篇文章的性质是把C语言中一些对于现在的我不是很符合预期的知识点记录一下. ■ HelloWorld程序 HelloWorl ...

  8. Variational RL for POMDP

    1.Le, Tuan Anh, et al. "Auto-encoding sequential monte carlo." arXiv preprint arXiv:1705.1 ...

  9. 五、005-环境安装【docker、fabric】

    1.参考地址:https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html#install-curl 一.前置条件和系统配置 1.安 ...

  10. Android手机用wifi连接adb调试的方法

    https://www.jianshu.com/p/dc6898380e38 0x0 前言 Android开发肯定要连接pc的adb进行调试,传统的方法是用usb与pc进行连接,操作简单即插即用,缺点 ...