Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. /*  He He He He よろしくお願いします
  2. */
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define DB(_x)      cout << #_x << " is " << (_x) << "\n";
  7. #define fs          first
  8. #define sc          second
  9. #define pb          push_back
  10. //#define IOFILE
  11.  
  12. using LL = long long;
  13. using LD = long double;
  14. using VI = vector<int>;
  15. using PI = pair<int,int>;
  16. using PPI = pair<int,PI>;
  17. const int mod = 1e9 + 7;
  18. const int mxn = 1e6;
  19.  
  20. /*
  21. ** Global variables
  22. */
  23.     int m, n, k, cnt;
  24.     queue<PI> Q;
  25.     map<PI,PI> PA;
  26. void Excalibur(){
  27. //    cin >> m >> n >> k;
  28.     m = 5; n = 4; k = 3; cnt = 0;
  29.  
  30.     Q.push({0,0});
  31.     PA[{0,0}] = {0,0};
  32.  
  33.     while (Q.size()){
  34.         int bottle_A = Q.front().fs;
  35.         int bottle_B = Q.front().sc;
  36.         cout << "i = " << bottle_A << " " << bottle_B << "\n";
  37.         if (bottle_A == k || bottle_B == k){
  38.             cout << cnt;
  39.             return;
  40.         }
  41.  
  42.         ++cnt;
  43.         Q.pop();
  44.  
  45.         /*
  46.         ** B first then A
  47.         */
  48.  
  49.         /*
  50.         ** Đổ qua bình khác(3), đổ đầy bình(1), đổ ra ngoài(2)
  51.         */
  52.         int bottle_Temp_B;
  53.         int bottle_Temp_A;
  54.  
  55.         // Đổ đầy bình
  56.         set<PI> S;
  57.         bottle_Temp_B = n;
  58.         bottle_Temp_A = bottle_A;
  59.         S.insert({bottle_Temp_A,bottle_Temp_B});
  60.  
  61.         // Đổ đầy bình
  62.         bottle_Temp_A = m;
  63.         bottle_Temp_B = bottle_B;
  64.         S.insert({bottle_Temp_A,bottle_Temp_B});
  65.  
  66.         // Đổ ra ngoài
  67.         bottle_Temp_B = 0;
  68.         bottle_Temp_A = bottle_A;
  69.         S.insert({bottle_Temp_A,bottle_Temp_B});
  70.  
  71.         // Đổ ra ngoài
  72.         bottle_Temp_A = 0;
  73.         bottle_Temp_B = bottle_B;
  74.         S.insert({bottle_Temp_A,bottle_Temp_B});
  75.  
  76.         // Đổ từ B(n) sang A(m)
  77.         bottle_Temp_B = max(0, bottle_A + bottle_B - m);
  78.         bottle_Temp_A = min(m, bottle_A + bottle_B);
  79.         S.insert({bottle_Temp_A,bottle_Temp_B});
  80.  
  81.         //Đổ từ A(m) sang B(n)
  82.         bottle_Temp_A = max(0, bottle_A + bottle_B - n);
  83.         bottle_Temp_B = min(n, bottle_A + bottle_B);
  84.         S.insert({bottle_Temp_A,bottle_Temp_B});
  85.  
  86.         cout << "T(i) \n";
  87.         for (auto x: S){
  88.             cout << x.fs << " " << x.sc << "\n";
  89.             if (PA.count({x.fs,x.sc}) == 0){
  90.                 PA[{x.fs,x.sc}] = {bottle_A, bottle_B};
  91.                 Q.push({x.fs,x.sc});
  92.             }
  93.         }
  94.         cout << "Open \n";
  95.         queue<PI> temp_queue = Q;
  96.         while (temp_queue.size()){
  97.             cout << temp_queue.front().fs << " " << temp_queue.front().sc << "\n";
  98.             temp_queue.pop();
  99.         }
  100.  
  101.         cout << "---End---\n";
  102.     }
  103.  
  104. }
  105.  
  106. int main(){
  107. ios::sync_with_stdio(false);
  108. //cin.tie(nullptr);
  109. //cout.tie(nullptr);
  110.  
  111. #ifdef  IOFILE
  112.     freopen("INPUT.in", "r", stdin);
  113.     freopen("OUTPUT.out", "w", stdout);
  114. #endif
  115.  
  116. Excalibur();
  117. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement