Uva-571-jugs (number theory-classic pour water problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.