#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. DES加密解密算法C语言代码实现

    代码: #include<stdio.h> #include<string.h> #include<stdlib.h> /*-------------------- ...

  2. Eclipse SVN clean up失败解决方法

    错误信息: 1.下载sqlite3.zip  (https://www.sqlite.org/2019/sqlite-tools-win32-x86-3270200.zip) 只需用到解压后的exe文 ...

  3. mysql查询前几条记录

    #My SQL 取前多少条select * from table LIMIT 5,10; #返回第6-15行数据 select * from table LIMIT 5; #返回前5行 select ...

  4. Gradle 打可执行jar包

    初次使用Gradle,想和maven一样,把gradle项目打成可执行jar包,具体步骤: 1.下载gradle 版本,并配置环境变量, 下载地址:https://gradle.org/release ...

  5. 如何保持github的fork于主干同步

    step1: https://help.github.com/articles/configuring-a-remote-for-a-fork/ step2: https://help.github. ...

  6. CNN(卷积神经网络)、RNN(循环神经网络)、DNN,LSTM

    http://cs231n.github.io/neural-networks-1 https://arxiv.org/pdf/1603.07285.pdf https://adeshpande3.g ...

  7. tf训练OTSU

    训练一个简单的回归网络 基础的函数如下: # coding=utf-8 import tensorflow as tf import numpy as np np.random.seed(0) # 卷 ...

  8. mac使用minikube

    brew install kubectl 需要加代理! minikube start --vm-driver=xhyve --docker-env HTTP_PROXY=http://your-htt ...

  9. JAVA中有一个特殊的类: Object。它是JAVA体系中所有类的父类(直接父类或者间接父类)。

    接口往往被我们定义成一类XX的东西. 接口实际上是定义一个规范.标准.   ①  通过接口可以实现不同层次.不同体系对象的共同属性: 通过接口实现write once as anywhere. 以JA ...

  10. Ubuntu 16.04 ROS环境配置

    最近新入职一家公司,是搞智能无人驾驶的,用的操作系统是Ubuntu和ros,之前没接触过ros系统,既然公司用那就必须的学习啊,话不多说先装它一个ros玩玩... 1. Ubuntu 安装 ROS K ...