题意:可以把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(); }

最新文章

  1. 代码中,使用__DATE__宏,获取程序编译时间,如何保证每次编译代码(非重新生成方式),都能更新__DATE__的值?
  2. java生成excel文件
  3. Nginx 的编译安装和URL地址重写
  4. 【leetcode】First Missing Positive
  5. HDU 3341 状态压缩DP+AC自动机
  6. 基于Jquery Validate 的表单验证
  7. 解决maven打jar包报错 source 1.3 中不支持
  8. xctool工具
  9. SharePoint 设置Lookup 字段的值
  10. C语言实现数据结构中的堆创建,堆排序
  11. Android中利用Camera与Matrix实现3D效果详解
  12. cuda编程-矩阵乘法(1)
  13. 006 Spark中的wordcount以及TopK的程序编写
  14. 使用limma、Glimma和edgeR,RNA-seq数据分析易如反掌
  15. vue项目在IE下报错&quot;strict 模式下不允许一个属性有多个定义&quot;
  16. 对动态加载javascript脚本的研究
  17. form enctype:&quot;multipart/form-data&quot;,method:&quot;post&quot; 提交表单,后台获取不到数据
  18. 学习python第四天——Oracle分组
  19. 洛谷P1880 [NOI1995] 石子合并 [DP,前缀和]
  20. html中通过移除空格的方法来解决浏览器上的留白间距该怎么理解?

热门文章

  1. Eclipse Unhandled event loop exception GC overhead limit exceeded
  2. curl重写php file_get_contents
  3. Spring Boot系列——Spring Boot如何启动
  4. 关于c语言的左移运算
  5. tensorflow 笔记10:tf.nn.sparse_softmax_cross_entropy_with_logits 函数
  6. linux每日命令(14):less命令
  7. 解决SQLite异常:library routine called out of sequence
  8. idea配置项目运行时内存大小
  9. .NET实现事务的编码方式
  10. Go_14:GoLang中 json、map、struct 之间的相互转化