#include <iostream>
using namespace std;
int main()
{
int ca,cb,N,A,B;
int temp;
while(cin>>ca>>cb>>N)
{
A = B = 0;
while(A!=N && B!=N)
{
if(A == 0)
{
cout<<"fill A"<<endl;
A = ca;
}
if(B == cb)
{
cout<<"empty B"<<endl;
B = 0;
}
cout<<"pour A B"<<endl;
temp = (cb > A+B) ? (A+B) : cb;
A = (cb >= A+B) ? 0 : (A+B-cb);
B = temp;
}
if(A==N)
{
if(B!=0)
{
cout<<"empty B"<<endl;
}
cout<<"pour A B"<<endl;
}
cout<<"success"<<endl;
}
return 0;
}
这个题目的意思比较难理解。本来应该用DFS(深度优先搜索)来做的。但是题目"A and B are relatively prime to one another"这句话表明A和B互素。了解数论的的知识就应该知道这样倒一定解(我对数论了解甚少,我估计应该是一定有最优解)。