hdu 2717 Catch That Cow(BFS,剪枝)
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct tt
{
int step,tem;
};
int visit[];
queue <tt> q; int bfs(tt s,tt e)
{
tt front,temp;
q.push(s);
visit[s.tem]=;
while(!q.empty())
{
front=q.front();
q.pop();
temp.step=front.step+;
temp.tem=front.tem+;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=; temp.tem=front.tem-;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=; temp.tem=front.tem*;
if(temp.tem==e.tem)
return temp.step;
else if(temp.tem>=&&temp.tem<=&&visit[temp.tem]==) q.push(temp),visit[temp.tem]=;
}
return ;
} int main()
{
tt s,e;
int ans;
while(scanf("%d%d",&s.tem,&e.tem)!=EOF)
{
s.step=;
memset(visit,,sizeof(visit));
while(!q.empty())
q.pop();
if(s.tem<e.tem)
ans=bfs(s,e);
else
ans=s.tem-e.tem;
printf("%d\n",ans);
}
return ;
}
hdu 2717 Catch That Cow(BFS,剪枝)的更多相关文章
- 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 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 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)
题目链接: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 ...
- 题解报告:hdu 2717 Catch That Cow(bfs)
Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...
- HDOJ/HDU 2717 Catch That Cow 一维广度优先搜索 so easy..............
看题:http://acm.hdu.edu.cn/showproblem.php?pid=2717 思路:相当于每次有三个方向,加1,减1,乘2,要注意边界条件,减1不能小于0,乘2不能超过最大值. ...
随机推荐
- 为什么ARM的frq中断的处理速度比较快
FRQ向量位于异常向量表的最末端,不需要跳转就可以直接执行后面跟随的异常处理程序:FRQ模式中私有寄存器数量最多,在进行异常处理时不需要对这些寄存器进行压栈保存.
- 《LDAP服务器和客户端的加密认证》RHEL6——第二篇 运维工程师必考
服务端的配置: (基于原先配好的ldap服务器)打开加密认证: Iptables –F setenforce 0 1.编辑ldap的配置文件:slapd.conf 2.启动ldap服务器: 3.切换 ...
- JQuery window.opener
$('#Save').click(function () { var parent = $(parent.document.body); $(parent).find('input#add ...
- Silverlight形状、画笔、变换、图像处理、几何图形
1.形状(Ellipse.Line.Path.Polygon.Polyline 和 Rectangle) <UserControl x:Class="SharpStudy.MainPa ...
- sql server 中更改默认实例
因为安装了多个版本的sql server,会造成同时存在多个实例的情况. 1.关闭旧版本的sql server实例,并设置为手动启动 2.按下图步骤操作,把tcp端口设置为1433 3.重启sql s ...
- PHP中strtotime函数使用方法分享
在PHP中有个叫做strtotime的函数.strtotime 实现功能:获取某个日期的时间戳,或获取某个时间的时间戳.strtotime 将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间 ...
- MVVM模式的一个小例子
使用SilverLight.WPF也有很长时间了,但是知道Binding.Command的基本用法,对于原理性的东西,一直没有深究.如果让我自己建一个MVVM模式的项目,感觉还是无从下手,最近写了一个 ...
- Zend-MVC intro
Zend-MVC intro Zend MVC层建立在servicemanager.eventmanager.http.stdlib.几个组件之上.相关组件介绍会在其他文章中详细说明. 除了以上4大组 ...
- oracle-12c-rac 报:ORA-01078
OS: Oracle Linux Server release 5.7 DB: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - ...
- 详解C/C++预处理器
C/C++编译系统编译程序的过程为预处理.编译.链接.预处理器是在程序源文件被编译之前根据预处理指令对程序源文件进行处理的程序.预处理器指令以#号开头标识,末尾不包含分号.预处理命令不是C/C++语 ...