$CF1141A Game 23$
这题很简单啊 可以用\(DFS\)来打
毕竟是 \(2^x*3^y=m 输出x+y啊\)
这是最简单的做法
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : f = 1 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ; return res * f ;
}
int n , m ;
int ans = 0x7f7f7f7f;
inline void dfs(int x,int step) {//x是当前数值 step是步数
if(x > m) return ;
if(x == m) {//符合条件
cout << step << endl ;//输出
exit(0);//这个同return 0; 不过适用于函数中
}
dfs(x<<1,step+1) , dfs(x*3,step+1) ;
}
signed main () {
n = In() , m = In() ;
dfs(n,0) ;
if(ans == 0x7f7f7f7f) cout << -1 << endl ;
return 0 ;
}
随机推荐
- Mac 当xampp里mysql无法启动的解决办法
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
- vuex----mutation和action的基本使用
我们要实现的很简单,就是点击+1的count加一,点击-1的时候count-1 一.mutation 在vue 中,只有mutation 才能改变state. mutation 类似事件,每一个mu ...
- java 8新特性 匿名内部类的使用
package com.atguigu.java8; import java.util.ArrayList; import java.util.Arrays; import java.util.Com ...
- shrink&split
shrink将分片数按因子缩减.hard link segment文件.因缩减前后hash一致,不需要rehash.如:0 ,1 , 2, 3, 4, 5, 6, 7, 8.9个分片缩减成3个:0 [ ...
- free web rich code eidtor
free web rich code eidtor https://i.cnblogs.com/Preferences.aspx tiny code-editor https://apps.tiny. ...
- [luoguP1111] 修复公路(并查集)
传送门 呵呵的最小生成树 ——代码 #include <cstdio> #include <iostream> #include <algorithm> #defi ...
- mappingLocations、mappingDirectoryLocations与mappingJarLocations 区别 (转)
mappingLocations.mappingDirectoryLocations与mappingJarLocations 区别 由于spring对hibernate配置文件hibernate.cf ...
- PatentTips – GPU Saving and Restoring Thread Group Operating State
BACKGROUND OF THE INVENTION The present invention relates generally to single-instruction, multiple- ...
- BIV+CSS网页的标准化布局
DIV用于搭建网站结构(框架),CSS用于创建网站表现(样式/美化) DIV+CSS模式设计网站的优势: 1.表现和内容分离. 2代码简洁,提高网页浏览速度. 3.易于维护,改版. 4.提高搜索引擎对 ...
- Spring Boot在开发时实现热部署(开发时修改文件保存后自动重启应用)(spring-boot-devtools)
热部署是什么 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果,往往需要重启应用查看改变效果,其实就是重新编译生成了新的Class文件,这个文件里记录着和代码等对应的各 ...