题目

#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,剪枝)的更多相关文章

  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 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. 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 ...

  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. 题解报告:hdu 2717 Catch That Cow(bfs)

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

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

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

随机推荐

  1. 跨frame操作dom元素

    今天,一群友问到跨frame操作dom元素的问题.于是写了个demo,在此发表在博客里面,供其他同道中人参考! 创建child.html内容如下: <!DOCTYPE HTML PUBLIC & ...

  2. Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.

    Error: An App ID with identifier "*****" is not avaliable. Please enter a different string ...

  3. 基于FPGA的图像去噪

    目录 结构图 其中FPGA 控制模块为核心,通过它实现视频图像数据的获取.缓存.处理和控制各模块间通讯[1].由CCD 相机对目标成像,高速图像数据由camera link 实时传输[2],经信号转换 ...

  4. php intval()函数

    格式:int intval(mixed $var [, int $base]); 1.intval()的返回值是整型,1或者0.可作用于数组或者对象(对象报错信息:Notice: Object of ...

  5. java 环境变量设置

    JAVA_HOME  C:\Program Files\Java\jdk1.7.0 PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; CLASSPATH .;%JAV ...

  6. Zendframework application 引导过程

    Applications 会期望用户提供一个配置好的ServiceManager.提供以下服务: 1.EventManager 2.ModuleManager 3.Request 4.Response ...

  7. ActiveMQ之Queue

    Queue实现的是点到点模型,在以下的例子中,启动2个消费者共同监听一个Queue,然后循环给这个Queue发送多个消息. 代码如下: public class QueueTest { /** * @ ...

  8. 【转载】MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry

    原文地址:MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry 作者:忆雨林枫 刚配置的MySQL主从, ...

  9. [SQL_Server_Question]Msg 1105无法为数据库 'tempdb' 中的对象分配空间,因为 'PRIMARY' 文件组已满

    错误消息: Msg 1105, Level 17, State 2, Line 266Could not allocate space for object 'dbo.Large Object Sto ...

  10. 2016 系统设计第一期 (档案一)jQuery ajax serialize()方法form提交数据

    jQuery ajax serialize()方法form提交数据,有个很奇怪的问题,好像不能取到隐藏控件的值. //点击提交按钮保存数据 $('#btn_submitUser').click(fun ...