题意:可以把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. redis-desktop-manager 的简单使用

    1:安装比较简单,所有软件几乎都一样(下载.安装)我就从安装好后,怎么玩记录吧!如下图,双击对应的图标就能打开此软件了 2-1:连接redis服务器的方式之一——导入对应的redis信息 连接配置的样 ...

  2. Android源码阅读笔记二 消息处理机制

    消息处理机制: .MessageQueue: 用来描述消息队列2.Looper:用来创建消息队列3.Handler:用来发送消息队列 初始化: .通过Looper.prepare()创建一个Loope ...

  3. 使用python抓取58手机维修信息

    之前在ququ的博客上看到说 python 中的BeautifulSoup 挺好玩的,今天下午果断下载下来,看了下api,挺好用的,完了2把,不错. 晚上写了一个使用python抓取58手机维修信息的 ...

  4. iOS开发支付宝支付

    iOS支付宝支付(Alipay)详细接入流程以及项目中遇到的问题分析    浏览: 149 发布日期: 2016-10-19  分类: ios 最近在项目中接入了微信支付和支付宝支付,总的来说没有那么 ...

  5. js中关于Blob对象的介绍与使用

    js中关于Blob对象的介绍与使用   blob对象介绍 一个 Blob对象表示一个不可变的, 原始数据的类似文件对象.Blob表示的数据不一定是一个JavaScript原生格式 blob对象本质上是 ...

  6. Linux磁盘概念及其管理工具fdisk

    Linux磁盘概念及其管理工具fdisk [日期:2016-08-27] 来源:Linux社区  作者:chawan [字体:大 中 小]   引言:冯诺依曼体系中的数据存储器就是我们常说的磁盘或硬盘 ...

  7. Spark学习笔记——Spark上数据的获取、处理和准备

    数据获得的方式多种多样,常用的公开数据集包括: 1.UCL机器学习知识库:包括近300个不同大小和类型的数据集,可用于分类.回归.聚类和推荐系统任务.数据集列表位于:http://archive.ic ...

  8. windows下添加多个git仓库账号

    当使用git方式下载时,如果没有配置过ssh key,会提示错误(git clone支持https和git(即ssh)两种方式下载源码) 当需要在机器上使用不同的git账户,这就需要知道如何在机器上添 ...

  9. 【转】QT Graphics-View官方介绍(中文翻译)

    一.GraphicsView框架简介 QT4.2开始引入了Graphics View框架用来取代QT3中的Canvas模块,并作出了改进,Graphics View框架实现了模型-视图结构的图形管理, ...

  10. eclipse去掉所有断点 恢复到默认窗口

    1.去掉所有断点 Window->Open Perspective->Debug默认是右上角的窗口中,切换到Breakpoints,如果里边有内容,那就是设置断点啦,点叉叉全部删掉就好了. ...