题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数。

坑:标题写了。有点不会写bfs了。。。

ac代码

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
const int maxn = 1e5 + ;
int vis[maxn];
struct node {
int x, t;
node(int n = , int k = ) :x(n), t(k) {}
}; int n, k;
bool check(int x) {
if ( x > 1e5 || x < || vis[x])return ;
else return ;
}
void Run() {
queue<node> Q;
Q.push(node(n,));
vis[n] = ;
while (!Q.empty()) {
node now = Q.front();
Q.pop(); if (now.x == k) { cout << now.t; break; }
if (check(now.x + ))Q.push(node(now.x + , now.t + )),vis[now.x + ] = ;
if (check(now.x - ))Q.push(node(now.x - , now.t + )), vis[now.x - ] = ;
if (check(now.x * ))Q.push(node(now.x * , now.t + )), vis[now.x * ] = ; }
} void smain() { cin >> n >> k; Run(); }

Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。的更多相关文章

  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. C - Catch That Cow POJ - 3278

    //标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...

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

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

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

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

  7. POJ 3278 Catch That Cow(模板——BFS)

    题目链接:http://poj.org/problem?id=3278 Description Farmer John has been informed of the location of a f ...

  8. Catch That Cow (简单BFS+剪枝)

    Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...

  9. POJ:3259-Wormholes(最短路判断负环)

    Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 58153 Accepted: 21747 Descripti ...

随机推荐

  1. golang ----gc问题

    go程序内存占用大的问题 这个问题在我们对后台服务进行压力测试时发现,我们模拟大量的用户请求访问后台服务,这时各服务模块能观察到明显的内存占用上升.但是当停止压测时,内存占用并未发生明显的下降.花了很 ...

  2. Android UI系列-----长度单位和内外边距

    这篇随笔将会记录一下在控件布局时,设定距离的三种长度单位:px.dp.sp以及内外边距的属性 1.三种长度单位 ①px:px是我们常见的一种距离单位,它表示的是一个单位像素,我们经常说我们手机或者电脑 ...

  3. SNF快速开发平台MVC-Grid++集成打印

    一.显示效果: 二.程序实现: 1.先要在 打印模版程序 给指定页面进行在线设计打印模版 2.在使用的程序当中,增加如下代码即可.程序上是可以挂多个打印模版的,程序页面的代码不用动直接可以读取到打印模 ...

  4. 2. RabbitMQ 服务器 之下载安装

    RabbitMQ服务器如何安装? RabbitMQ是一个AMQP(Advanced Message Queue,即高级消息队列协议)服务器 . 下载地址: RabbitMQ下载 安装说明:各平台下Ra ...

  5. pandas DataFrame(2)-行列索引及值的获取

    pandas DataFrame是二维的,所以,它既有列索引,又有行索引 上一篇里只介绍了列索引: import pandas as pd df = pd.DataFrame({'A': [0, 1, ...

  6. 用Python来玩微信跳一跳

    微信2017年12月28日发布了新版本,在小程序里面有一个跳一跳小游戏,试着点一点玩了下.第二天刚好在一篇技术公众号中,看到有大神用Python代码计算出按压时间,向手机发送android adb命令 ...

  7. golang 命令行cobra妙用

    为什么使用命令行 大型项目中少不了数据升级,如果采用web服务,一来不够安全,二来数据量大的时候也会出超时的情况.这时使用命令行是比较合适的方式了. 命令行中的MVC web项目一般采用MVC模式,对 ...

  8. Nginx的upstream目前支持5种分配方式

    本文转自:http://mp.weixin.qq.com/s?__biz=MzI4OTU3ODk3NQ==&mid=2247484058&idx=1&sn=f4da816bfa ...

  9. ELK 性能(4) — 大规模 Elasticsearch 集群性能的最佳实践

    ELK 性能(4) - 大规模 Elasticsearch 集群性能的最佳实践 介绍 集群规模 集群数:6 整体集群规模: 300 Elasticsearch 实例 141 物理服务器 4200 CP ...

  10. Java知多少(79)哈希表及其应用

    哈希表也称为散列表,是用来存储群体对象的集合类结构. 什么是哈希表 数组和向量都可以存储对象,但对象的存储位置是随机的,也就是说对象本身与其存储位置之间没有必然的联系.当要查找一个对象时,只能以某种顺 ...