Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* He He He He よろしくお願いします
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define DB(_x) cout << #_x << " is " << (_x) << "\n";
- #define fs first
- #define sc second
- #define pb push_back
- //#define IOFILE
- using LL = long long;
- using LD = long double;
- using VI = vector<int>;
- using PI = pair<int,int>;
- using PPI = pair<int,PI>;
- const int mod = 1e9 + 7;
- const int mxn = 1e6;
- /*
- ** Global variables
- */
- int m, n, k, cnt;
- queue<PI> Q;
- map<PI,PI> PA;
- void Excalibur(){
- // cin >> m >> n >> k;
- m = 5; n = 4; k = 3; cnt = 0;
- Q.push({0,0});
- PA[{0,0}] = {0,0};
- while (Q.size()){
- int bottle_A = Q.front().fs;
- int bottle_B = Q.front().sc;
- cout << "i = " << bottle_A << " " << bottle_B << "\n";
- if (bottle_A == k || bottle_B == k){
- cout << cnt;
- return;
- }
- ++cnt;
- Q.pop();
- /*
- ** B first then A
- */
- /*
- ** Đổ qua bình khác(3), đổ đầy bình(1), đổ ra ngoài(2)
- */
- int bottle_Temp_B;
- int bottle_Temp_A;
- // Đổ đầy bình
- set<PI> S;
- bottle_Temp_B = n;
- bottle_Temp_A = bottle_A;
- S.insert({bottle_Temp_A,bottle_Temp_B});
- // Đổ đầy bình
- bottle_Temp_A = m;
- bottle_Temp_B = bottle_B;
- S.insert({bottle_Temp_A,bottle_Temp_B});
- // Đổ ra ngoài
- bottle_Temp_B = 0;
- bottle_Temp_A = bottle_A;
- S.insert({bottle_Temp_A,bottle_Temp_B});
- // Đổ ra ngoài
- bottle_Temp_A = 0;
- bottle_Temp_B = bottle_B;
- S.insert({bottle_Temp_A,bottle_Temp_B});
- // Đổ từ B(n) sang A(m)
- bottle_Temp_B = max(0, bottle_A + bottle_B - m);
- bottle_Temp_A = min(m, bottle_A + bottle_B);
- S.insert({bottle_Temp_A,bottle_Temp_B});
- //Đổ từ A(m) sang B(n)
- bottle_Temp_A = max(0, bottle_A + bottle_B - n);
- bottle_Temp_B = min(n, bottle_A + bottle_B);
- S.insert({bottle_Temp_A,bottle_Temp_B});
- cout << "T(i) \n";
- for (auto x: S){
- cout << x.fs << " " << x.sc << "\n";
- if (PA.count({x.fs,x.sc}) == 0){
- PA[{x.fs,x.sc}] = {bottle_A, bottle_B};
- Q.push({x.fs,x.sc});
- }
- }
- cout << "Open \n";
- queue<PI> temp_queue = Q;
- while (temp_queue.size()){
- cout << temp_queue.front().fs << " " << temp_queue.front().sc << "\n";
- temp_queue.pop();
- }
- cout << "---End---\n";
- }
- }
- int main(){
- ios::sync_with_stdio(false);
- //cin.tie(nullptr);
- //cout.tie(nullptr);
- #ifdef IOFILE
- freopen("INPUT.in", "r", stdin);
- freopen("OUTPUT.out", "w", stdout);
- #endif
- Excalibur();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement