UVA_571
There was no idea at first, and later I came to the others' report and found that they were done in a greedy way.
Because this question does not limit the number of times of pouring water, we only need to construct A feasible solution. If we add water every time A is empty, we will pour water to B, when B is full, empty is dropped. In this way, any solution between 0 and B can be formed in B.
Later, I proved it easily. If we pour water in this way, we can use (n * A) % B to represent the amount of water in B. Because of the mutual quality of A and B, it is easy to get that the minimum cycle of this function is B, and in a period, we can easily prove that the values of this function are different, and the values of n in a period (accurately two critical points must be included) are 0-B, then the corresponding value will inevitably overwrite 0-B, so we can get an operation sequence that meets the requirements.
#include<stdio.h>
#include<string.h>
int Ca, Cb, N;
void solve()
{
int i, j, k, a, b;
a = b = 0;
for(;;)
{
if(b == N)
{
printf("success\n");
break;
}
else if(b == Cb)
{
printf("empty B\n");
b = 0;
}
if(!a)
{
printf("fill A\n");
a = Ca;
}
printf("pour A B\n");
if(a + b > Cb)
{
a = a + b - Cb;
b = Cb;
}
else
{
b += a;
a = 0;
}
}
}
int main()
{
while(scanf("%d%d%d", &Ca, &Cb, &N) == 3)
{
solve();
}
return 0;
}