kuangbin专题 专题一 简单搜索 Catch That Cow POJ - 3278
题目链接:https://vjudge.net/problem/POJ-3278
题意:人可以左移动一格,右移动一格,或者移动到当前位置两倍下标的格子
思路:把题意的三种情况跑bfs,第一个到达目的地的时间最短。
#include <iostream>
#include <string.h>
#include<queue>
#include <algorithm>
using namespace std; #define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--) const int N = 1e5 + ;
int mv[] = { -, , };//2表示跳跃
bool vis[N];
int n, k; struct node{
int x, c;
}; //判断是否在界限内
inline bool check(int x){
return x >= && x <= ;
} void bfs(){ vis[n] = true;
queue<node> que;
que.push(node{n,}); //直接抓到
if (n == k){
cout << << endl;
return;
} int dx;
while (!que.empty()){
node tmp = que.front();
que.pop(); rep(i, , ){
if (i == ) dx = tmp.x << ;//跳跃 dx = tmp.c * 2
else dx = tmp.x + mv[i]; //是否在界限内且没被访问
if (check(dx) && !vis[dx]){
vis[dx] = true;//标记访问过了 //抓到了
if (dx == k){
cout << tmp.c + << endl;
return;
}
else que.push(node{ dx, tmp.c + });
}
}
} } int main(){ ios::sync_with_stdio(false);
cin.tie(); cin >> n >> k;
bfs(); return ;
}
kuangbin专题 专题一 简单搜索 Catch That Cow POJ - 3278的更多相关文章
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- (广搜)Catch That Cow -- poj -- 3278
链接: http://poj.org/problem?id=3278 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6211 ...
- Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。
题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include& ...
- C - Catch That Cow POJ - 3278
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...
- kuangbin专题总结一 简单搜索
A - 棋盘问题:在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
- kuangbin专题 专题一 简单搜索 Shuffle'm Up POJ - 3087
题意:(1)有两副颜色多样的扑克牌,(A~H)表示不同颜色,给你两副牌,S1,S2和一副你需要洗出的KEY,S12由S2最底部,S1底部...一直下去,直到洗成S12,就是图片展示的那样.(2)洗好的 ...
- [kuangbin带你飞]专题一 简单搜索(回顾)
A - 棋盘问题 POJ - 1321 注意条件:不能每放一个棋子,就标记一行和一列,我们直接枚举每一行就可以了. AC代码: #include<iostream> #include< ...
- kuangbin专题——简单搜索
A - 棋盘问题 POJ - 1321 题意 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大 ...
随机推荐
- Prism框架在项目中使用
本文大纲 1.Prism框架下载和说明 2.Prism项目预览及简单介绍. 3.Prism框架如何在项目中使用. Prism框架下载和说明 Prism框架是针对WPF和Silverlight的MVVM ...
- C++中类的继承与Java中的不同,C++的派生类不能继承父类的构造函数和析构函数(不一定正确)
http://blog.csdn.net/guodongxiaren/article/details/24885023
- 基于树莓派的微型气象站设计与开发(Windows 10 IoT Core)
前言 树莓派(Raspberry Pi,RPi)是专门为学生计算机编程教育而设计,只有信用卡大小的卡片式电脑,可以运行Linux或者Windows 10 IoT Core操作系统.本文将利用树莓派和U ...
- wpf 禁用window的systemmenu
private IntPtr WidProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (m ...
- php将两个数组相同的key合并到一个数组
$arr = array( array( 'id' => 1, 'user_name'=>'test1' ), array( 'id' =& ...
- LINQ查询表达式---------where子句
LINQ查询表达式---------where子句 where 子句用在查询表达式中,用于指定将在查询表达式中返回数据源中的哪些元素. 它将一个布尔条件(“谓词”)应用于每个源元素(由范围变量引用), ...
- MongoDB.Driver 管道 Aggregate
目前mongodb for C#这个驱动,在进行Aggregate时,只支持BsonDocument类型,也就是说,你的集合collection也必须返回的是BsonDocument,而实体类型是不可 ...
- css的圣杯布局
圣杯布局和双飞翼布局实现的效果是一样的. 代码解析: 1.四个section,container,main,left,right.其中那个container为父容器. 2.main,left,righ ...
- Java Date Calendar DateFormat Details
From https://www.ntu.edu.sg/home/ehchua/programming/java/DateTimeCalendar.html Date and Time - Creat ...
- SSL Converter & Formats
https://www.sslshopper.com/ssl-converter.html PEM Format The PEM format is the most common format th ...