Pots
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 7821 | Accepted: 3278 | Special Judge |
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 potj is full (and there may be some water left in the poti), or the poti is empty (and all its contents have been moved to the potj).
- Write a program to find the shortest possible sequence of these operations that will yield exactlyC liters of water in one of the pots.
Input
On the first and only line are the numbers A, B, andC. These are all integers in the range from 1 to 100 andC≤max(A,B).
Output
The first line of the output must contain the length of the sequence of operationsK. The followingK 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 be achieved, the first and only line of the file must contain the word ‘impossible’.
Sample Input
3 5 4
Sample Output
6 FILL(2) POUR(2,1) DROP(1) POUR(2,1) FILL(2) POUR(2,1)
Source
Northeastern Europe 2002, Western Subregion
思路:用BFS,表示从此状态到目标状态,中间判断是否与之前状态是否重复,如果重复则不让其进入队列。
关键:表示状态及状态间转移,判断是否重复!在处理状态的时候,不管起始什么状态都按呢几种状态处理!从而可以忽略好的情况的判断。
思路:用BFS,表示从此状态到目标状态,中间判断是否与之前状态是否重复,如果重复则不让其进入队列。
关键:表示状态及状态间转移,判断是否重复!在处理状态的时候,不管起始什么状态都按呢几种状态处理!从而可以忽略好的情况的判断。