Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int N, tmpDb = 0, best = 0, startRequest = 1;
  7. int Method1(int, int);
  8. int Method2(int, int);
  9.  
  10. int main()
  11. {
  12.     cin >> N;
  13.  
  14.     int best = 0;
  15.     for (int i = 0; i < 4; i++)
  16.     {
  17.         startRequest = i;
  18.         best = max(Method1(N, i), best);
  19.         if ((N + i) % 3 == 0 && i != 0) break;
  20.     };
  21.     cout << best << endl;
  22. }
  23.  
  24. int Method1(int full, int empty)
  25. {
  26.     tmpDb += full;
  27.     //cout << "full: " << full << endl;
  28.     empty += full;
  29.     //cout << "empty: " << empty << endl;
  30.     if (empty >= startRequest && full < 3)
  31.     {
  32.         int toReturn = tmpDb;
  33.         tmpDb = 0;
  34.         return toReturn;
  35.     }
  36.     return Method1(empty / 3, full / 3);
  37. }
  38.  
  39. int Method2(int full, int empty)
  40. {
  41.     tmpDb += full;
  42.     //cout << "full: " << full << endl;
  43.     empty += full;
  44.     //cout << "empty: " << empty << endl;
  45.     if (empty >= startRequest && full < 3)
  46.     {
  47.         int toReturn = tmpDb;
  48.         tmpDb = 0;
  49.         return toReturn;
  50.     }
  51.     return Method2(empty / 3, (empty / 3) % 3);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement