简单的广搜:

#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. Windows窗口消息大全(转)

    Windows窗口消息大全,全不全自己看 ////////////////////////////////////////////////////////////////////////// #inc ...

  2. 开源libusb驱动的libwdi驱动安装API库和zadig.exe安装UI应用程序的编译和调试

    一.目的 二.编译环境 系统:Win7 ~ Win10 编译工具:Visual Studio 2008 或 Visual Studio 2010 或Visual Studio 2015 libwdi编 ...

  3. leetcode 60. Permutation Sequence(康托展开)

    描述: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...

  4. Aliyun EMR 集群重启

    1.如果Core节点有Down掉,ActiveNodes少于Core节点数. 处理: a.登陆到Master节点,到目录 /opt/apps/hadoop-2.7.2/sbin b.执行 ./stop ...

  5. 【Android】Handler的应用(一):从服务器端加载JSON数据

    最终目的 以JSON的形式,将数据存入服务器端. 在Android中,以Handler加载显示大批量文字. 在此以加载金庸小说<天龙八部(新修版)>为例(2580480 字节). 以tom ...

  6. R与数据分析旧笔记(三)不知道取什么题目

    连线图 > a=c(2,3,4,5,6) > b=c(4,7,8,9,12) > plot(a,b,type="l") 多条曲线效果 plot(rain$Toky ...

  7. 优秀的 Android Studio 插件

    转自:http://www.codeceo.com/article/8-android-studio-plugins.html Android Studio是目前Google官方设计的用于原生Andr ...

  8. check the manual that corresponds to your MySQL server version for the right syntax的错误解析

    错误原因一:SQL关键字冲突 分析:例:把desc命名为字段名 错误原因二:$right=$DB->fetch_one_array("SELECT rsnumber FROM &quo ...

  9. 解析ECC与RECC内存之间的区分

    普通的定义上区分:内存,是连接CPU 和其他设备的通道,起到缓冲和数据交换作用.当CPU在工作时,需要从硬盘等外部存储器上读取数据,但由于硬盘这个“仓库”太大,加上离CPU也很“远”,运输“原料”数据 ...

  10. Jsoup代码解读之二-DOM相关对象

    Jsoup代码解读之二-DOM相关对象   之前在文章中说到,Jsoup使用了一套自己的DOM对象体系,和Java XML API互不兼容.这样做的好处是从XML的API里解脱出来,使得代码精炼了很多 ...