Pouring water

All submissions for this problem are available.
Given two vessels, one of which can accommodate a liters of water and the other which can accommodate b liters of water, determine the number of steps required to obtain exactly c liters of water in one of the vessels.
At the beginning both vessels are empty. The following operations are counted as 'steps':
 emptying a vessel,
 filling a vessel,
 pouring water from one vessel to the other, without spilling, until one of the vessels is either full or empty.
Input
An integer t, 1<=t<=100, denoting the number of test cases, followed by t sets of input data, each consisting of three positive integers a (the number of liters the first container can hold), b (the number of liters the second container can hold), and c (the final amount of liters of water one vessel should contain), not larger than 40000, given in separate lines.
Output
For each set of input data, output the minimum number of steps required to obtain c liters, or 1 if this is impossible.
Example
2 5 2 3 2 3 4
Sample output:
2 1
Author:  admin 
Tags  admin 
Date Added:  1122008 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 
plz giv mre test examples....
there r only 3 cases case
there r only 3 cases
case 1:
a==c or b==c then print 1
case 2:
ab==c or ba==c then print 2
case 3:
else print 1
if there r any more cases plz tell thnx.....
Suppose a=7 , b=5 and c=6
Suppose a=7 , b=5 and c=6 then for that case you will have following steps
a b
0 0
0 5
5 0
5 5
7 3
0 3
3 0
3 5
7 1
0 1
1 0
1 5
6 0
or for the above case the
or for the above case the better way will be
a b
0 0
7 0
2 5
2 0
0 2
7 2
4 5
4 0
0 4
7 4
6 5
plz explain for the case
plz explain for the case when
a=5,b=6,c=3;
0 0 0 6 5 1 0 1 1 0 1 6 5 2 0
0 0
0 6
5 1
0 1
1 0
1 6
5 2
0 2
2 0
2 6
5 3
or
0 0
5 0
0 5
5 5
4 6
4 0
0 4
5 4
3 6
Hi, if we take a=5 b= 6 c=3
Hi,
if we take a=5 b= 6 c=3 then my output is 8 steps but if a=6 b=5 c=3 then my output steps are 10 and this goes for all combinations i am following the algo
Code:
while A != C && B != C
if A is empty fill A
else if B is full empty B
else pour from A to B
wend
i am getting wrong answer when i submit my solution so i just wanna confirm is this the reason?????
Well the answer for those two
Well the answer for those two test cases obviously should be the same. If you aren't getting the same answer, then you must be wrong.
what will be the answer if
what will be the answer if any one of the a, b or c=0??
sorry, got it!!
sorry, got it!!
fed up with these
fed up with these WA's....someone plss help!!!!!
admin plss help!!! dnt knw
admin plss help!!! dnt knw where m i going wrong.....getting ryt answers on my system... :( :(
Iv written the
Iv written the program..
Everything is fine in my output screen..
but when i submit here it shows Time limit exceeded. Can anybody tell me the basic mistakes for time limit exceeding in this program?
Admin, please help. My
i cant understand the problem
@admin can u please give some
Is it necessary that all the
Can anyone tell a case with c
^^ if a=6 ,b=4 and c=3 then
what is wrong with my code
Sir , Please tell me
awesome question!! after 8
Wow, brute force worked here.
using BFS will work