简单的广搜:

#include <cstdio>
#include <queue>
using namespace std; int map[],step[];
int n,start,end,res; bool check(int x)
{
if ((x>)&&(x<)&&(map[x])) return true;
else return false;
} int bfs()
{
int temp;
if(start==end) return res;
queue<int> Q;
Q.push(start);
step[start]=;
map[start]=false;
while(!Q.empty())
{
temp=Q.front();
Q.pop();
if (temp+==end) return step[temp]+;
if (temp-==end) return step[temp]+;
if (temp*==end) return step[temp]+;
if (check(temp+))
{
int now=temp+;
Q.push(now);
step[now]=step[temp]+;
map[now]=false;
}
if (check(temp-))
{
int now=temp-;
Q.push(now);
step[now]=step[temp]+;
map[now]=false;
}
if (check(temp*))
{
int now=temp*;
Q.push(now);
step[now]=step[temp]+;
map[now]=false;
}
}
return -;
} int main()
{
while(scanf("%d%d",&start,&end)!=EOF)
{
for(int i=;i<;i++)map[i]=true;
res=; res=bfs();
printf("%d\n",res);
}
return ;
}

HDU 2717 Catch That Cow的更多相关文章

  1. HDU 2717 Catch That Cow --- BFS

    HDU 2717 题目大意:在x坐标上,农夫在n,牛在k.农夫每次可以移动到n-1, n+1, n*2的点.求最少到达k的步数. 思路:从起点开始,分别按x-1,x+1,2*x三个方向进行BFS,最先 ...

  2. HDU 2717 Catch That Cow (bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Ot ...

  3. HDU 2717 Catch That Cow(常规bfs)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Oth ...

  4. HDU 2717 Catch That Cow(BFS)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  5. hdu 2717:Catch That Cow(bfs广搜,经典题,一维数组搜索)

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. hdu 2717 Catch That Cow(广搜bfs)

    题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...

  7. 杭电 HDU 2717 Catch That Cow

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. HDOJ/HDU 2717 Catch That Cow 一维广度优先搜索 so easy..............

    看题:http://acm.hdu.edu.cn/showproblem.php?pid=2717 思路:相当于每次有三个方向,加1,减1,乘2,要注意边界条件,减1不能小于0,乘2不能超过最大值. ...

  9. HDU 2717 Catch That Cow (深搜)

    题目链接 Problem Description Farmer John has been informed of the location of a fugitive cow and wants t ...

  10. 题解报告:hdu 2717 Catch That Cow(bfs)

    Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...

随机推荐

  1. HDFS之HBase伪分布安装

    1.HBase简介 HBase是Apache Hadoop中的一个子项目,Hbase依托于Hadoop的HDFS作为最基本存储基础单元,通过使用hadoop的DFS工具就可以看到这些这些数据 存储文件 ...

  2. linux使用wget纯命令下载JDK的方法(凑字数)

    linux使用wget纯命令下载JDK的方法 linux使用wget纯命令下载JDK的方法 Oracle官网上下载jdk,需要点击accept licence的才能下载,所以一般的直接使用wget下载 ...

  3. hdu 3572 Escape 网络流

    题目链接 给一个n*m的图, 里面有一些点, '.'代表空地, '#'代表墙, 不可以走, '@'代表大门, 可以有多个, 'X'代表人, 问所有人都走出大门需要的最短时间, 每一时刻一个格子只能有一 ...

  4. 【Delphi内联汇编学习1】Delphi与汇编

    我一直认为Delphi功能与C++相比毫不逊色,提供了丰富的控件和类.全部API以及嵌入的汇编.最近小弟在把C版的Huffman压缩改用Delphi写时,顺便“研究”了一下Delphi的位操作和嵌入式 ...

  5. VS2010/MFC对话框:文件对话框

    文件对话框 上一讲介绍的是消息对话框,本节讲解文件对话框.文件对话框也是很常用的一类对话框. 文件对话框的分类       文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中 ...

  6. oracle 11g RAC Grid Infrastructure

    grid infrastructure 软件介质下载: http://www.oracle.com/technetwork/database/database-technologies/cluster ...

  7. Sharepoint 2013 --系统安装配置

    参考博客: http://www.cnblogs.com/jianyus/archive/2013/02/01/2889653.html 安装操作系统->改机器名->装AD->装DN ...

  8. window 7 改变窗口颜色

    对于刚刚重新安装的window7系统的盆友来说,不能改变窗口的颜色,和别人的window7窗口颜色和样子不一样和不好玩,那么我教大家,如何更改窗口颜色. 首先,重装的系统用软件激活之后,肯定还没还得急 ...

  9. MVC下载Excel

    方法1: public ActionResult DownExcel() { var stream = list.Select(p => new { p.UserName, p.Mobile, ...

  10. Unity cg vertex and fragment shaders(二)

    着色器的一般结构: Shader "MyShader/MyShaderName" { Properties { // ... properties here ... } SubSh ...