#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. 生产环境CPU过高问题定位

    问题描述:       生产环境下的某台tomcat7服务器,在刚发布时的时候一切都很正常,在运行一段时间后就出现CPU占用很高的问题,基本上是负载一天比一天高. 解决过程: 1.根据top命令,发现 ...

  2. Effective Java 第三版—— 86. 非常谨慎地实现SERIALIZABLE接口

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  3. Effective Java 第三版——63. 注意字符串连接的性能

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  4. Shell脚本编程(三):shell参数传递

    我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 实例 以下实例我们向脚本传递三 ...

  5. hdoj:2070

    Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. PCL点云配准(3)

    (1)关于点云的配准 1.首先给定源点云与目标点云. 2.提取特征确定对应点 3.估计匹配点对应的变换矩阵 4.应用变换矩阵到源点云到目标点云的变换 配准的流程图 通过特征点的匹配步骤 (1)计算源点 ...

  7. mysqldump定时备份数据库

    mysql服务器ip:192.168.0.10 备份服务器ip:192.168.0.11 数据库名称:db_product 思路:在mysql服务器A上创建一个用户分配权限专门用于数据库备份,A服务器 ...

  8. 分析“HTTP500内部服务器错误”解决方法

    系统中出现的一些故障是用户最不想看到的,有时候遇到一些故障都到折腾个大半天才能够搞定.打开网站出现了HTTP500内部服务器错误的提示,无法法查看错误的详细信息,用户也没办法根据具体的问题来解决,这对 ...

  9. What is a TensorFlow Session?

    Sep 26, 2016 I've seen a lot of confusion over the rules of tf.Graph and tf.Session in TensorFlow. I ...

  10. 和TransDecoder 学习perl 自定义模块的路径问题

    TransDecoder 软件是用perl 原因写的,其中包含了一些自定义的模块,通过一个脚本来进行调用,为了能够正常访问自定义的perl 模块, 在其源代码中利用了FindBin 这个模块 use ...