#P1432. Water Jug Puzzle
Water Jug Puzzle
Water Jug Puzzle
Given two jugs, A and B, with capacities \(C_a\) and \(C_b\) respectively, and an unlimited water supply, you are allowed to perform the following operations:
- fill A: Fill jug A to its full capacity.
- fill B: Fill jug B to its full capacity.
- empty A: Empty jug A.
- empty B: Empty jug B.
- pour A->B: Pour water from jug A into jug B. The pouring stops either when jug A becomes empty or jug B becomes full.
- pour B->A: Pour water from jug B into jug A. The pouring stops either when jug B becomes empty or jug A becomes full.
Your task is to output a sequence of valid operations that results in exactly \(N\) units of water in jug B. Note that during a pouring operation, if jug A is used to pour into jug B and either jug A runs out of water or jug B becomes full, you must immediately stop pouring.
For example, if jug A has a capacity of 5 gallons and jug B has a capacity of 6 gallons, and you start with \(8\) gallons of water in jug A, then when pouring from A to B, jug B becomes full and jug A will be left with 3 gallons.
inputFormat
The input consists of three integers \(C_a\), \(C_b\), and \(N\) separated by spaces. Here, \(C_a\) and \(C_b\) denote the capacities of jug A and jug B respectively, and \(N\) is the target amount of water that must be exactly contained in jug B.
outputFormat
Output a sequence of operations (one per line) that transforms the state such that jug B contains exactly \(N\) units of water. The allowed operations are:
- fill A
- fill B
- empty A
- empty B
- pour A->B
- pour B->A
If no sequence of operations exists, output "No solution.".
sample
5 6 4
fill A
pour A->B
fill A
pour A->B
empty B
pour A->B
</p>