//标准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. access 连接数据库

    前提条件 如果没有安装office的话,需要安装引擎 安装了office就不用安装引擎 连接数据库 Dim plMydb As Microsoft.Office.Interop.Access.Dao. ...

  2. appium(4)-Automating mobile web apps

    Automating mobile web apps If you’re interested in automating your web app in Mobile Safari on iOS o ...

  3. 诡异的json包含bom头

    今日项目碰到 需要调用php的一个接口  结果一直报返回的json字符串转对象  bom头报错 Exception in thread "main" com.fasterxml.j ...

  4. Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表

    题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...

  5. 整合kxmovie

    下载后发现kxmovie 直接运行是不通的,上面我们已经处理了ffmpeg部分的内容.当然了先处理ffmpeg部分.然后再复制kxmovie/kxmovie到项目中导入相应的文件. 编译报错:UIim ...

  6. laravel基础课程---3、路由(Laravel中的常见路由有哪几种)

    laravel基础课程---3.路由(Laravel中的常见路由有哪几种) 一.总结 一句话总结: 6种:post,get,put,patch,delete,options Route::get($u ...

  7. SecureCRT自动备份脚本-思科

    利用SecureCRT脚本对思科设备进行批量备份: (1)新建文本文件(注意保存路径,本次测试路径为D:\backup\list.txt): x.x.x.x username password ena ...

  8. yolo-开源数据集coco kitti voc

    1.kitti数据集(参考博客:https://blog.csdn.net/jesse_mx/article/details/65634482  https://blog.csdn.net/baoli ...

  9. 【linux+C】神器 vim + 指针相关客串

    前篇回顾 上篇介绍了linux下C编程基本环境配置以及相关工具使用选择. 不过10个大牛9个用vim,那么咱们就来玩vim.linux下玩c就别依靠图形界面.好吧告别Ide,命令行才是c的王道. 本篇 ...

  10. jni中c代码调用java代码

    原理是使用反射的机制 java中反射的例子: Class<?> forName = Class.forName("com.example.ndkcallback.DataProv ...