can only pour in one direction, such as C1=3,c2=5,a b from 0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1->1 5->3 3->0 3->0 0, back to 0 0, and backwards pushed back just as C1 has been to C2 down, because 0*c2%c1->1*c2%c1->...->c1*c2%c1==0
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 inta,b,n,c1,c2;7 8 voidSlove ()9 {TenPuts"Fill B"); One if(c2==N) A { -Puts"Success"); - return; the } -b=0; - while(1)//b always to a pour, at n!=a when B must first reach N, if a to B pour when a to n and pour to B that - { +b+=C2; - while(b>C1) + { APuts"pour B A"); atb-=C1; - if(b==N) - { -Puts"Success"); - return ; - } inPuts"Empty A"); - } toPuts"pour B A"); +Puts"Fill B"); - } the } * $ intMain ()Panax Notoginseng { - while(SCANF ("%d%d%d", &c1,&c2,&n) = =3) the { + if(n==0|| N>C2) A { thePuts"Success"); + Continue; - } $ slove (); $ } - return 0; -}
View Code
UVA 571 jugs ADD18 Small Petition 10 Math Part1 Special