Topic Transfer: UVA-571
Idea: A is empty when the full, not empty will pour to the b,b full after the full fall, until the capacity of B is n (reference)
AC Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set > #include <deque> #include <cctype> #define LL long long#define INF 0x7fffffffusing namespace Std;int Main ( ) {int A, B, CA, CB, N;while (scanf ("%d%d%d", &ca, &CB, &n)! = EOF) {A = 0, B = 0;while (1) {if (b = = N) {print F ("success\n"); break;} else if (b = = cb) {printf ("Empty b\n"); b = 0;} else if (a = = 0) {printf ("Fill a\n"); a = CA;} else if (A = 0) {printf ("pour a b\n"), if (A + B <= cb) {B + = A, a = 0;} else A = a + B-CB, B = cb;}}} return 0;}
Uva-571-jugs (number theory-classic pour water problem)