题目

题意:

给你两个数 a , b a,b a,b,问你是否存在 a a a左移/右移后会得到 b b b,如果存在的话,每次可以移位 1 , 2 , 3 1,2,3 1,2,3位,最少移动几次。

思路:

我们只要先判断是否存在,如果 b / a = 2 k b/a=2^k b/a=2k存在的话,那么就说明肯定能通过移位实现,然后我们每次进行除 8 8 8操作,这样每次就可以除最大,更快的得到 a a a。(条件:b>a)

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {char c;int sgn;if (c = getchar(), c == EOF) return ;while (c != '-' && (c < '0' || c > '9')) c = getchar();sgn = (c == '-') ? -1:1;ret = (c == '-') ? 0:(c - '0');while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');ret *= sgn;return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
int main() {int t;read(t);while (t--) {ll a, b;read(a), read(b);if (a > b) swap(a, b);if (a == b) {printf("0\n");continue;}ll x = b / a;if (b % a == 0 && (x & (x - 1)) == 0) {ll ans = 0;while (b > a) {b /= 8;ans++;}printf("%lld\n", ans);} else printf("-1\n");}return 0;
}

codeforces A. Johnny and Ancient Computer相关推荐

  1. CodeForces - 1362E Johnny and Grandmaster(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个基数 p ,再给出 n 个指数 k ,换句话说,现在有一个长度为 n 的序列,每个元素都是 p^k[ i ] ,现在需要将这个序列分到两个集合中,使得两个集合元素 ...

  2. codeforces 935E Fafa and Ancient Mathematics 语法树、动态规划

    题解 一道很有意思的题目,同时把动态规划和语法树结合起来,很有新意,思路我是想出来了,但是我的写法较为麻烦,从别人的submission中找了一个写起来简介的代码分享给大家. 看到表达式的形式,我们可 ...

  3. Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!(AB)

    Johnny and Ancient Computer CodeForces - 1362A 思路:因为除或者乘的都是2的幂次,所以看看二者的商是不是2的幂次就可以了.如果是的话,就3,2,1依次就行 ...

  4. codeforces:1361(div1)1362(div2):总结

    文章目录 前言 1362-A. Johnny and Ancient Computer 解析 1362-B - Johnny and His Hobbies 解析 1362-C - Johnny an ...

  5. Educational Codeforces Round 115 (Rated for Div. 2) A. Computer Game

    题目链接:Problem - 1598A - Codeforces Monocarp is playing a computer game. Now he wants to complete the ...

  6. Codeforces H. Ancient Wisdom

    题目链接:https://codeforces.com/gym/102365/problem/H H. Ancient Wisdom David and Aram had the following ...

  7. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  8. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp

    D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...

最新文章

  1. 零基础快速学习Java技术的方法整理
  2. linux火狐浏览器49.0安装教程,firefox for linux
  3. 【VC基础】3、配置参数文件
  4. (视频+图文)机器学习入门系列-第13章 降维
  5. oracle0数据库论文总结,大学oracle数据库总结(考试必备)
  6. PyCharm和git安装教程
  7. linux消息总线日志,linux – 解密继续mpt2sas系统日志消息
  8. layui-简单辅助元素 - 页面元素
  9. solr mysql 分词_solr学习篇(二) solr 分词器篇
  10. 错误调试:Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4
  11. [NLP]OpenNLP块检测器(Chunker)的使用
  12. 影响世界的100个经典管理定律
  13. 小武与retinanet的斗争
  14. Android logo图标的尺寸
  15. 重定向和转发的区别(redirect和forward)
  16. 基恩士CSV点云文件转PCD文件 PYTHON版
  17. 金融衍生品PK:期权和权证俩兄弟
  18. 尽己力,听天命。无愧于心,不惑于情
  19. 转 怎么回答“分布式架构”才能让面试官满意?
  20. CDISC SDTM IE domain学习笔记

热门文章

  1. java socket客户端设计,基于JavaSocket多客户端并发通信聊天程序的设计与实现
  2. 【SemiDrive源码分析】【MailBox核间通信】47 - 分析RPMSG_IPCC_RPC 方式 单次传输的极限大小 及 极限带宽测试(理论分析篇)
  3. Jetpack Compose助我快速打造电影App
  4. 苹果项目关闭服务器,iphone系统服务哪些可以关闭
  5. 考虑特性分布的储能电站接入的电网多时间尺度源储荷协调调度策略(Matlab代码实现)
  6. 苹果iPad mini 2真机泄露 仍存疑点
  7. 8-figma-文字工具
  8. 【总结】游戏AI人工智能
  9. 【iapp源码】UI界面很简洁的方盒子iapp源码
  10. 数字纪念馆设计案例,科技助力见证历史!