题目传送:UVA - 571
思路:A为空时就加满,不空就倒给B,B满了后就全倒掉,直到B的容量为n(参考)
AC代码:
#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 0x7fffffff using 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) { printf("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 (数论 - 经典倒水问题)
原文地址:http://blog.csdn.net/u014355480/article/details/45344023