#include #include #include #include

using namespace std;

const int N = 110;

int n, m, k; struct Node{ int a, b; string op; }; bool st[N][N]; void bfs(){ queue q; q.push({0, 0, ""}); st[0][0] = true; while(q.size()) { auto t = q.front(); q.pop(); if(t.a == k || t.b == k){ cout << t.op.size() << endl; for(auto c : t.op) cout << c << endl; return; } if(!st[n][t.b]) q.push({n, t.b, t.op + "FILL(1) "}), st[n][t.b] = true; if(!st[t.a][m]) q.push({t.a, m, t.op + "FILL(2) "}), st[t.a][m] = true; if(!st[0][t.b]) q.push({0, t.b, t.op + "DROP(1) "}), st[0][t.b] = true; if(!st[t.a][0]) q.push({t.a, 0, t.op + "DROP(2) "}), st[t.a][0] = true; int x = min(t.a, m - t.b); if(!st[t.a - x][t.b + x]) q.push({t.a - x, t.b + x, t.op + "POUR(1,2) "}), st[t.a - x][t.b + x] = true; int y = min(t.b, n - t.a); if(!st[t.a + y][t.b - y]) q.push({t.a + y, t.b - y, t.op + "POUR(2,1) "}), st[t.a + y][t.b - y] = true; } puts("impossible"); }

int main(){ cin >> n >> m >> k; bfs(); return 0; }


原文地址: https://www.cveoy.top/t/topic/lBXF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录