POUR1 - Pouring water
Given two vessels, one of which can accommodate a litres of water and the other - b litres of water, determine the number of steps required to obtain exactly c litres 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.
An integer t, 1<=t<=100, denoting the number of testcases, followed by t sets of input data, each consisting of three positive integers a, b, c, not larger than 40000, given in separate lines.
For each set of input data, output the minimum number of steps required to obtain c litres, or -1 if this is impossible.
2 5 2 3 2 3 4
I think BFS is bad here
i love qianqian
-1 .. nguenthanhloc
Doing through BFS+maps too. But TLE. Using the following algorithm.
Actual problem: You are at the side of a river. You have a "a" liter jug and a "b" liter jug. The jugs do not have markings to allow measuring smaller quantities. How canyou use the jugs to measure "c" liter of water?
My 69th. BFS + maps :D
Is there a math formula for this question?
My 100th.. .Beginners believe in yourself . YOU CAN SOLVE IT. Dont rely on spojtoolkit for this question.Last edit: 2016-08-12 21:13:54
AC Java : GCD along with logic(if conditions)
0.29 sec using bfs+map and 0.00 using eea,, nice question, worth the time;