ZOJ Problem Set

注意,条件:B>=C 。应考虑B=C的情况。

#include<iostream>
using namespace std;

int A,B,C;

void jugs(int a,int b,int C)
{
    if(b==C)
    {
        cout<<"success"<<endl;
        
    }
    else if(b==B)
    {
        cout<<"empty B"<<endl;
        jugs(a,0,C);
    }
    else if(a==0)
    {
        cout<<"fill A"<<endl;
        cout<<"pour A B"<<endl;
        if(A+b>=B)
        {
            a=A-(B-b);                
            cout<<"empty B"<<endl;
            jugs(a,0,C);
        }
        else
        {
            jugs(0,b+A,C);
        }            
    }
    else
    {
        cout<<"pour A B"<<endl;
        if(a+b>=B)
        {
            a=A-(B-b);                
            cout<<"empty B"<<endl;
            jugs(a,0,C);
        }
        else
        {
            jugs(0,a+b,C);
        }        
    }
    return;

}

int main()
{
    while(cin>>A>>B>>C)
    {

        if (A==C)
        {
            cout<<"fill A"<<endl;
            cout<<"success"<<endl;
            continue;
        }
        if (B==C)
        {
            cout<<"fill B"<<endl;
            cout<<"success"<<endl;
            continue;
        }
        jugs(0,0,C);
    }
    return 0;
}

1.需找bug,参考:

http://www.cnblogs.com/phinecos/archive/2008/09/21/1295472.html

原文地址:https://www.cnblogs.com/yaolei/p/3748758.html