tungSfer

S-T

May 18th, 2021 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el endl
  5. #define umi unordered_map<int, int>
  6. #define umll unordered_map<ll, ll>
  7. #define all(vect) vect.begin(), vect.end()
  8. #define reset(A) memset(A, 0, sizeof(A))
  9. #define approx(n) fixed << setprecision(n)
  10.  
  11. const int mod = 1e9 + 7;
  12.  
  13. using namespace std;
  14.  
  15. void solve()
  16. {
  17.     ll st, en;
  18.     cin >> st >> en;
  19.     queue<ll> q;
  20.     q.push(st);
  21.     umll mp;
  22.     mp[st] = 1;
  23.     if(st == en)
  24.     {
  25.         cout << 0 << el;
  26.         return;
  27.     }
  28.     while(true)
  29.     {
  30.         ll te = q.front();
  31.         mp[te]++;
  32.         q.pop();
  33.         if(te == en)
  34.         {
  35.             break;
  36.         }
  37.         if(!mp[te - 1])
  38.             q.push(te - 1);
  39.         if(!mp[te * 2])
  40.             q.push(te * 2);
  41.        
  42.     }
  43.     ll count = mp.size();
  44.     if(count)
  45.         cout << (ll)log2(count) << el;
  46. }
  47. int main()
  48. {
  49.     int t = 1;
  50.     cin >> t;
  51. //  cin.ignore();
  52.     while(t--)
  53.     {
  54.         solve();
  55.     }
  56.     return 0;
  57. }
  58.  
  59.  
  60.  
Add Comment
Please, Sign In to add comment