题目

以前做过,所以现在觉得很简单,需要剪枝,注意广搜的特性;

另外题目中,当人在牛的前方时,人只能后退。

#define  _CRT_SECURE_NO_WARNINGS
//这是非一般的最短路,所以广搜到的最短的路不一定是所要的路线
//所以应该把所有的路径都搜索出来,找到最短的转折数,看他是不是不大于2
//我是 用边搜索边更新当前路径的最小转弯数 来写的
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 100010
bool vis[MAXN];
int s,t; struct tt
{
int x,step;
}; int bfs()
{
tt front,rear,temp;
queue<tt>q;
while(!q.empty())
q.pop();
memset(vis,false,sizeof(vis));
front.x=s;front.step=;
q.push(front);
vis[s]=true;
while(!q.empty())
{
temp=q.front();
if(temp.x==t)
return temp.step;
q.pop();
rear.step=temp.step+; if(temp.x>t)
{
rear.x=temp.x-;
if(rear.x>=&&rear.x<=MAXN&&!vis[rear.x])
q.push(rear),vis[rear.x]=true;
}
else
{
rear.x=temp.x+;
if(rear.x>=&&rear.x<=MAXN&&!vis[rear.x])
q.push(rear),vis[rear.x]=true; rear.x=temp.x-;
if(rear.x>=&&rear.x<=MAXN&&!vis[rear.x])
q.push(rear),vis[rear.x]=true; rear.x=temp.x*;
if(rear.x>=&&rear.x<=MAXN&&!vis[rear.x])
{
q.push(rear);
vis[rear.x]=true;
}
}
}
return ;
} int main()
{
while(scanf("%d%d",&s,&t)!=EOF)
{
if(s>t)
printf("%d\n",s-t);
else
{
printf("%d\n",bfs());
}
}
return ;
}

poj 3278 Catch That Cow (广搜,简单)的更多相关文章

  1. BFS POJ 3278 Catch That Cow

    题目传送门 /* BFS简单题:考虑x-1,x+1,x*2三种情况,bfs队列练练手 */ #include <cstdio> #include <iostream> #inc ...

  2. POJ 3278 Catch That Cow(赶牛行动)

    POJ 3278 Catch That Cow(赶牛行动) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Farmer J ...

  3. POJ 3278 Catch That Cow (附有Runtime Error和Wrong Answer的常见原因)

    题目链接:http://poj.org/problem?id=3278 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  4. poj 3278:Catch That Cow(简单一维广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45648   Accepted: 14310 ...

  5. POJ - 3278 Catch That Cow 简单搜索

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  6. POJ 3278 Catch That Cow(BFS,板子题)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 88732   Accepted: 27795 ...

  7. hdu 2717 Catch That Cow(广搜bfs)

    题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...

  8. POJ 3278 Catch That Cow(求助大佬)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 109702   Accepted: 34255 ...

  9. POJ 3278 Catch That Cow(BFS 剪枝)

    题目链接:http://poj.org/problem?id=3278 这几次都是每天的第一道题都挺顺利,然后第二道题一卡一天. = =,今天的这道题7点40就出来了,不知道第二道题在下午7点能不能出 ...

随机推荐

  1. 配置PostgreSQL Streaming Replication集群

    运行环境: Primary: 192.168.0.11 Standby: 192.168.0.21, 192.168.0.22 OS: CentOS 6.2 PostgreSQL: 9.1.2 版本以 ...

  2. u-boot ctr0.S详解 包含_main函数

    /** ****************************************************************************** * @author    Maox ...

  3. System Generator入门

      System generator 安装之后会在Simulin模块库中添加一些Xilinx FPGA专用的模块库,包括Basic Element,Communication,Control Logi ...

  4. lnmp下配置虚拟主机

    一:首先熟悉几个命令 which php      --->  which是通过 PATH环境变量到该路径内查找可执行文件,所以基本的功能是寻找可执行文件 whereis php   ----& ...

  5. windows下apache配置https

    1.下载带有openSSL的apache安装包,我下载的为apache_2.2.11-win32-x86-openssl-0.9.8i.msi,安装后确认一下bin路径下的openssl.exe,ss ...

  6. Mongodb学习教程汇总

    1.MongoDB权威指南 - 学习笔记 地址:http://www.cnblogs.com/refactor/category/394801.html 2.8天学通MongoDB 地址:http:/ ...

  7. jQuery实现用户注册的表单验证

    用户注册的表单往往是需要进行验证的,否则会有一些不否合规则的数据入库,后果会不堪设想,本文通过jquery来实现. <html>  <head>  <meta chars ...

  8. WebApp

    目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点,越来越流行. Hybrid App的兴起是现阶段移动互联网产业的一种偶然.移动互联 ...

  9. python time模块和datetime模块详解

    一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...

  10. 对现有Hive的大表进行动态分区

    分区是在处理大型事实表时常用的方法.分区的好处在于缩小查询扫描范围,从而提高速度.分区分为两种:静态分区static partition和动态分区dynamic partition.静态分区和动态分区 ...