题目

#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. Integer类的装箱和拆箱到底是怎样实现的?

    先解释一下装箱和拆箱: 装箱就是  自动将基本数据类型转换为包装器类型:拆箱就是  自动将包装器类型转换为基本数据类型. 下表是基本数据类型对应的包装器类型: int(4字节) Integer byt ...

  2. 如何在ARC代码中混编非ARC代码

    “ios中如果arc和非arc文件混编,可以在build parses中指定compile flags,如果arc文件设为"-fobjc-arc",非arc文件设为"-f ...

  3. RouterOS的MikroTik脚本从DNS更新IPSEC端的IP地址

    #Script for changing IPSEC address when DNS changes. #Script will iterate through all peers looking ...

  4. Oracle利用数据泵迁移用户

    一.利用数据泵将数据导出 1.1.确定字符集: select * from v$nls_parameters; 或 select userenv('language') from dual; 1.2. ...

  5. ros的源码阅读

    测试代码,使用xmlrpc与roscore通信 ros的框架是使用rpc与server端通信,server维护topic的publisher,subscriber,param server,servi ...

  6. poj 3237 Tree 树链剖分+线段树

    Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...

  7. synchronized 用法,实例讲解

    package com.asiainfolinkage.ems.web.controller.base; import java.math.BigInteger; import java.util.D ...

  8. HTTP 错误 404.3 - Not Found

    在使用win2012服务器上的IIS发布网页的时候,出现下面的错误 解决办法: 将应用程序开发下的所有功能都安装. 如果上面的方法没解决问题的话,那么看看下图中的这些安装没,没有的话就继续安装.

  9. 【rest】 深入理解rest

    起因是想搞明白 ajax.rest风格和http请求数据会有什么区别 再来回顾一下概念: REST即表述性 状态 传递 满足这些约束条件和原则的应用程序或设计就是RESTful.需要注意的是,REST ...

  10. jquery插件——图片放大器

    用到了JQzoom插件,可以使图片实现放大效果