HDU 2717 Catch That Cow
简单的广搜:
#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的更多相关文章
- 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,最先 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 2717:Catch That Cow(bfs广搜,经典题,一维数组搜索)
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- 杭电 HDU 2717 Catch That Cow
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDOJ/HDU 2717 Catch That Cow 一维广度优先搜索 so easy..............
看题:http://acm.hdu.edu.cn/showproblem.php?pid=2717 思路:相当于每次有三个方向,加1,减1,乘2,要注意边界条件,减1不能小于0,乘2不能超过最大值. ...
- HDU 2717 Catch That Cow (深搜)
题目链接 Problem Description Farmer John has been informed of the location of a fugitive cow and wants t ...
- 题解报告:hdu 2717 Catch That Cow(bfs)
Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...
随机推荐
- sql大数据量查询的优化技巧
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- Java I/O流操作(二)---缓冲流[转]
转自:http://blog.csdn.net/johnny901114/article/details/8710403 一.BufferWriter类 IO的缓冲区的存在就是为了提高效率,把要操作的 ...
- Java环境的配置
JAVA环境: 1.打开我的电脑--属性--高级--环境变量 2.将相应的JDK环境下载到本机,将路径保存到无中文路径中,并将路径复制下来. 3.在环境变量--系统变量,中新建 变量名:JAVA_HO ...
- vs vsvim viemu vax 备忘
使用gt和gT往返标签 gd:到达光标所在处函数或者变量的定义处. *:读取光标处的字符串,并且移动光标到它再次出现的地方. #:和上面的类似,但是是往反方向寻找. /text:从当前光标处开始搜索字 ...
- window.external.JavaScriptCallCpp
方案2: 1.编写html <html> <head> </head> <body> <script language="javascr ...
- 巧妙实现缺角radiogroup控制多个fragment切换和滑动
在android开发中,用一个radiogroup控制多个fragment切换是十分常见的需求.但是如果fragment是一个ListView,如何保证滑动的时候通过缺角可以看到下面的listview ...
- php中的require-once
require_once语句和require语句完全相同,唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含. 参见include_once的文档来理解_once的含义,并理解与没 ...
- FZU Problem 1686 神龙的难题 重复覆盖
题目链接 给出大矩形的长宽, 矩形里面有1,0两个值, 给出小矩形的长宽, 求用最少的小矩形覆盖所有的1. 重复覆盖的模板题. #include <iostream> #include & ...
- The basic introduction to MIX language and machine
reference: The MIX Computer, The MIX Introduction sets, The basic info storage unit in MIX computer ...
- HTML5速查表
HTML5速查表 标签 描述 版本 属性 <!--...--> 定义注释 4 / 5 none <!DOCTYPE> 定义文档类型 4 / 5 none <a> 定 ...