Description
You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:
FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;
DROP(i) empty the pot i to the drain;
POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j).
Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.
Input
On the first and only line are the numbers A, B, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).
Output
The first line of the output must contain the length of the sequence of operations K. The following K lines must each describe one operation. If there are several sequences of minimal length, output any one of them. If the desired result can’t

这是一个使用C语言解决的POJ 3414问题,目标是找到从两个不同容量的壶中得到特定体积水的最短操作序列。题目描述了三种可能的操作:填充、倒空和倒水。通过广度优先搜索(BFS)策略,找出所有可能的操作序列,并记录每个状态的前驱。当找到满足条件的序列时,返回其长度和具体操作。如果无法达到目标,则输出'不可能'。
最低0.47元/天 解锁文章
747

被折叠的 条评论
为什么被折叠?



