题目描述
During the admission talks, the Czech representatives meet with other diplomats from other countries. One day, after the dinner, the diplomats started to chat very informally. Among other things, they were discussing a scene from the movie `Die Hard 3''. In that movie, Bruce Willis and Samuel L. Jackson were confronted with the following puzzle: They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons.
The Czech representatives liked that puzzle very much and decided to generalize it. You are to write a program which can solve this generalized version. Assume you have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use:
· you can fill a jug,
· you can empty a jug, and
· you can pour from one jug to the other.
Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A.
A problem is given by a triple (CA, CB, N), where CA and CB are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in any of the jugs. The possible steps are:
· fill A
· fill B
· empty A
· empty B
· pour A B
· pour B A
· success
where `pour A B'' means `pour the contents of jug A into jug B'', and `success'' means that the goal has been accomplished.
输入
Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: CA, CB, and N. CA and CB are the capacities of jugs A and B, and N is the goal. You can assume 0 < CA ≤CB and N ≤ CB≤1000. You may also assume that the input you are given does have a solution.
输出
Output from your program will consist of a series of instructions from the list of the potential actions which will result in either of the jugs containing exactly N gallons of water. The last line of output for each puzzle should be the line `success''. After that line, output one empty line to terminate the puzzle.
The actions must be identified exactly as specified above. Output lines start in column 1 and there must be no empty lines and no trailing spaces.
The sequence of operations found by your program has to be as short as possible, i.e., you are to find the solution which requires the minimal number of steps. If more solutions with the same number of steps exist, choose any one of them.
fill B
pour B A
empty A
pour B A
fill B
pour B A
success
fill A
pour A B
fill A
pour A B
success
提示
Please note a little special meaning of evaluation system responses for this problem. If you get a `presentation error'', it may mean your program produces unknown actions or other unrecognized lines of output. On the other hand, `wrong answer'' means your program generates a valid list of actions but they do not represent the shortest solution.