Advertisement
double_trouble

Untitled

Oct 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.     int x, y;
  13.     cin >> x >> y;
  14.  
  15.     int x1 = min(x, y);
  16.     int y1 = max(x, y);
  17.  
  18.     cin >> x >> y;
  19.  
  20.     int x2 = min(x, y);
  21.     int y2 = max(x, y);
  22.  
  23.     if (x2 > x1 || y2 > y1)
  24.     {
  25.         cout << -1;
  26.         return 0;
  27.     }
  28.  
  29.     int ans = 0;
  30.     while (x1 != x2)
  31.     {
  32.         if (x1 - x2 > x2)
  33.         {
  34.             x1 = (x1 % 2) + (x1 / 2);
  35.         }
  36.         else
  37.             x1 = x2;
  38.         ans++;
  39.         if (x1 > y1)
  40.             swap(x1, y1);
  41.     }
  42.  
  43.     while (y1 != y2)
  44.     {
  45.         if (y1 - y2 > y2)
  46.         {
  47.             y1 = (y1 % 2) + (y1 / 2);
  48.         }
  49.         else
  50.             y1 = y2;
  51.         ans++;
  52.         if (x1 > y1)
  53.             swap(x1, y1);
  54.     }
  55.  
  56.     cout << ans;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement