Advertisement
AdamTheGreat

Untitled

Aug 5th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. bool check2equal(int a, int b, int c) {
  6.     if ((a == b && c == 0) || (a == c && b == 0) || (b == c && a == 0)) {
  7.         return true;
  8.     }
  9.     return false;
  10. }
  11.  
  12. int theother2[2] = {0, 0};
  13.  
  14. void getother2(int a) {
  15.     if (a == 0) {
  16.         theother2[0] = 1;
  17.         theother2[1] = 2;
  18.     } else if (a == 1) {
  19.         theother2[0] = 0;
  20.         theother2[1] = 2;
  21.     } else {
  22.         theother2[0] = 0;
  23.         theother2[1] = 1;
  24.     }
  25. }
  26.  
  27. int main(void) {
  28.     int cups[3] = {0};
  29.     int max[3];
  30.     cin >> max[0] >> max[1] >> max[2];
  31.     cups[0] = max[0];
  32.     queue<int> notebook;
  33.     notebook.push(0);
  34.     int counter = 0;
  35.     while (!notebook.empty()) {
  36.         int current = notebook.front();
  37.         notebook.pop();
  38.         for (int chossn = 0; chossn < 3; chossn++) {
  39.             getother2(chossn);
  40.             // cout << theother2[0] << " " << theother2[1] << endl;
  41.             for (int i = 0; i < 2; i++) {
  42.                 counter++;
  43.                 int over = 0;
  44.                 over = (cups[current]+cups[theother2[i]])%max[theother2[i]];
  45.                 if (over == 0) {
  46.                     cups[theother2[i]]+=cups[current];
  47.                     cups[current] = 0;
  48.                 } else {
  49.                     cups[theother2[i]] = max[theother2[i]];
  50.                     cups[current] = over;
  51.                 }
  52.                 notebook.push(theother2[i]);
  53.                 if (check2equal(cups[0], cups[1], cups[2])) {
  54.                 cout << cups[0] << " "  << cups[1] << " " << cups[2] << endl;
  55.                     return 0;
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement