题目

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

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

#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. C++ 11 之初始化

    1.4中不同初始化的形式     a.string s("zhl").int i(3);    //括号初始化     b.string s="zhl".int ...

  2. Java RMI 远程方法调用

    Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...

  3. 关于CORS

    前几天碰到CORS问题,只要在“Access-Control-Allow-Origin”响应头中添加对应域名即可. 今天做一个上传文件的demo,利用XMLHttpRequest向服务器发送post请 ...

  4. Viewport Resizer下载 谷歌前端自适应开发工具

    原文链接:http://www.phpbiji.cn/article/index/id/107/cid/6.html Viewport Resizer下载 谷歌前端自适应开发工具 在前端开发过程中,随 ...

  5. Css调整字体间距

    在span div 某些元素中有时候会用到调整字体的间距,设置方法: letter-spacing:15px;  

  6. How to change Form & Property & Report font for current User [AX2012]

    对于我们开发人员来说,系统默认的字体,本人实在不喜欢,尤其是属性字体[太小,太细,根本看不清],每次做一个新项目[AX2012]第一件事就是更改字体. 由于AX2012没有像AX2009那样,可以工具 ...

  7. Oracle bbed 实用示例-----修改Data内容、恢复delete的rows

    bbed 可以在db open 状态来进行修改,但是建议在做任何修改操作之前先shutdown db. 这样避免checkpoint 进程重写bbed 对block 的修改. 也避免oracle 在b ...

  8. Linq--扩展方法

    如果现在有一个这样的需求,求筛选出来的大于20MB的进程的和,常用的方法是写一个静态方法传进去一个ProcessData列表 比如: public static Int64 TotalMemory( ...

  9. Python解析HTML的开发库pyquery

    PyQuery是一个类似于jQuery的Python库,也可以说是jQuery在Python上的实现,能够以 jQuery 的语法来操作解析 HTML 文档,易用性和解析速度都很好. 例如,一段豆瓣h ...

  10. HDU 1405 第六周 J题

    Description Tomorrow is contest day, Are you all ready?  We have been training for 45 days, and all ...