//标准bfs
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue> using namespace std; int dir[] = { , - }; struct node
{
int x, step;
} s, ss; int bfs(int n, int k)
{
queue<node>q, qq;
s.x = n;
s.step = ;
int vis[] = { };
q.push(s);
while (!q.empty())
{
s = q.front();
q.pop();
if (s.x == k)
return s.step;
for (int i = ; i < ; i++)
{
ss.x = s.x + dir[i];
ss.step = s.step + ;
if (ss.x >= && ss.x <= )
if (!vis[ss.x])
{
vis[ss.x] = ;
q.push(ss);
}
}
ss.x = s.x * ;
ss.step = s.step + ;
if (ss.x >= && ss.x <= )
{
if (!vis[ss.x])
{
vis[ss.x] = ;
q.push(ss);
}
}
}
return ;
} int main()
{
int n, k;
while (~scanf("%d%d", &n, &k))
{
printf("%d\n", bfs(n, k));
}
return ;
}

C - Catch That Cow POJ - 3278的更多相关文章

  1. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  2. (广搜)Catch That Cow -- poj -- 3278

    链接: http://poj.org/problem?id=3278 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6211 ...

  3. Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索

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

  4. Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。

    题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include& ...

  5. kuangbin专题 专题一 简单搜索 Catch That Cow POJ - 3278

    题目链接:https://vjudge.net/problem/POJ-3278 题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子 思路:把题意的三种情况跑bfs,第一个到达目的地 ...

  6. BFS POJ 3278 Catch That Cow

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

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

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

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

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

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

随机推荐

  1. Delphi类的默认区域

    //类中数据成员的排列顺序一般是: 字段.方法.属性 //访问权限区域的顺序一般是:   无限制区(默认 published)   private   protected   public   pub ...

  2. 稳定币GUSD的优劣势分析

    在币圈,有人乘着牛市东风一夜暴富,也有人不幸赶上熊市倾家荡产,涨跌大起大落是币圈的常态,在如此不稳定的币市,投资者们都想寻求一些稳定.接着,稳定币诞生了. 2018年下半年,稳定币引起了各路投资者的高 ...

  3. STM32 ~ 外扩SRAM

    字节控制功能.支持高/低字节控制. 看看实现 IS62WV51216 的访问,需要对 FSMC进行哪些配置. 这里就做一个概括性的讲解.步骤如下: 1)使能 FSMC 时钟,并配置 FSMC 相关的  ...

  4. PAT天梯赛 L2-026. 小字辈 【BFS】

    题目链接 https://www.patest.cn/contests/gplt/L2-026 思路 用一个二维vector 来保存 每个人的子女 然后用BFS 广搜下去,当目前的状态 是搜完的时候 ...

  5. html5 canvas基本用法

    通过对canvas的初步了解,经过几天的总结,吧canvas的基本用法总结如下:方便以后查阅 <!doctype html> <html> <head> <m ...

  6. Codeforces Round #295 (Div. 2)---B. Two Buttons( bfs步数搜索记忆 )

    B. Two Buttons time limit per test : 2 seconds memory limit per test :256 megabytes input :standard ...

  7. WebDriver API——javascript的相关操作

    有些时候webdriver是没法操作元素或浏览器的,这时候我们可以通过javascript来进行相关的操作,昨天在群里一个朋友定位一个显示框,总是无法定位点击,或者是点击无效,这个时候就可以用java ...

  8. Java锁机制-重入锁

    锁的种类: 读写锁   悲观锁  乐观锁 CSA无锁  自旋锁  AQS 非公平锁 公平锁 互斥锁 排它锁  分布式锁(redis实现 和 zk实现) 轻量级锁(lock),重量级锁(synchron ...

  9. zkdash部署

    1.拉取代码 #git clone https://github.com/ireaderlab/zkdash.git 2.安装依赖包 #cd zkdash #yum install -y python ...

  10. 配置JDK和Tomcat环境变量(转)

    1.安装JDK 安装好JDK后,再配置JDK的环境变量:在“我的电脑”上点右键—>“属性”—>“高级”—> “环境变量(N)”. 新建系统变量JAVA_HOME:C:/Program ...