当前位置:网站首页>AcWing 4300. Two operations (minimum number of BFS searches)
AcWing 4300. Two operations (minimum number of BFS searches)
2022-07-06 22:56:00 【GHOSTANDBREAD】
Given a positive integer nn, We hope you can through a series of operations , Change it to another positive integer mm.
There are two kinds of operations :
- Multiply the current number by 22.
- Subtract... From the current number 11.
requirement , During the transformation , The number is always positive .
Please calculate , The minimum number of operations required .
Input format
a line , Two different positive integers nn and mm.
Output format
An integer , Indicates the minimum number of operations required .
Data range
front 66 Test points meet 1≤n,m≤101≤n,m≤10.
All test points meet 1≤n,m≤100001≤n,m≤10000.
sample input 1:
4 6
sample output 1:
2
sample input 2:
10 1
sample output 2:
9The code is as follows :
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m;
struct point{
int x;
int step=0;
};
queue<point> r;
int vis[200010];
int main()
{
ios::sync_with_stdio(false);
cout.tie(NULL);
memset(vis, 0, sizeof(vis));
cin >> n >> m;
point start;
start.x = n;
start.step = 0;
vis[n] = 1;
r.push(start);
while(!r.empty())
{
int xx = r.front().x;
if(xx == m){
cout<< r.front().step;
break;
}
for(int i = 0; i < 2; i ++)
{
int y;
if(i == 0 && xx < m) y = 2 * xx;
else{
y = xx - 1;
if(y <= 0){
continue;
}
}
if(vis[y] == 0){
point temp;
temp.x = y;
temp.step = r.front().step + 1;
vis[y] = 1;
r.push(temp);
}
}
r.pop();
}
return 0;
}边栏推荐
- [compilation principle] LR (0) analyzer half done
- [IELTS speaking] Anna's oral learning record part1
- Extern keyword
- CSDN 上传图片取消自动加水印的方法
- config:invalid signature 解决办法和问题排查详解
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- Void keyword
- 基于PaddlePaddle平台(EasyDL)设计的人脸识别课堂考勤系统
- [untitled]
- MySQL authentication bypass vulnerability (cve-2012-2122)
猜你喜欢

Traversal of a tree in first order, middle order, and then order

ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics

DR-Net: dual-rotation network with feature map enhancement for medical image segmentation

config:invalid signature 解决办法和问题排查详解

UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop

室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内

Bipartite graph determination

Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi

DR-Net: dual-rotation network with feature map enhancement for medical image segmentation

#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
随机推荐
Cocoscreator+typescripts write an object pool by themselves
UVa 11732 – strcmp() Anyone?
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
[IELTS speaking] Anna's oral learning record part1
MySQL authentication bypass vulnerability (cve-2012-2122)
How to use flexible arrays?
TypeScript获取函数参数类型
Use ECs to set up an agent
[leetcode] 19. Delete the penultimate node of the linked list
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
企業不想換掉用了十年的老系統
2022-07-05 use TPCC to conduct sub query test on stonedb
Extern keyword
动作捕捉用于蛇运动分析及蛇形机器人开发
Redis 持久化机制
memcached
Method of canceling automatic watermarking of uploaded pictures by CSDN
项目复盘模板
Improving Multimodal Accuracy Through Modality Pre-training and Attention
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面