#include #include #include using namespace std;int A,B,C,vis[101][101];char str[6][10] = { "FILL(1)", "FILL(2)", "DROP(1)", "DROP(2)", "POUR(1,2)", "POUR(2,1)"};structnode{ int num,a,b; node *pre;};node que[101*101];void print(node now){ if (now.pre) { print(*now.pre); printf("%s\n",str[now.num]); }}void BFS(){ int step=0,head=0,tail=1,count,water1,water2; que[0].a=que[0].b=0; que[0].pre=0; while (tail-head>0) { count=tail-head; while (count--) { node now=que[head]; if (now.a==C || now.b==C) { printf("%d\n",step); print(now); return; } if(!vis[A][now.b]) { vis[A][now.b]=1; que[tail].num=0; que[tail].a=A; que[tail].b=now.b; que[tail++].pre=&que[head]; } if(!vis[now.a][B]) { vis[now.a][B]=1; que[tail].num=1; que[tail].a=now.a; que[tail].b=B; que[tail++].pre=&que[head]; } if(!vis[0][now.b]) { vis[A][now.b]=1; que[tail].num=2; que[tail].a=0; que[tail].b=now.b; que[tail++].pre=&que[head]; } if(!vis[now.a][0]) { vis[now.a][0]=1; que[tail].num=3; que[tail].a=now.a; que[tail].b=0; que[tail++].pre=&que[head]; } water1=min (now.a,B-now.b); if(!vis[now.a-water1][now.b+water1]) { vis[now.a-water1][now.b+water1]=1; que[tail].num=4; que[tail].a=now.a-water1; que[tail].b=now.b+water1; que[tail++].pre=&que[head]; } water2=min (A-now.a,now.b); if(!vis[now.a+water2][now.b-water2]) { vis[now.a+water2][now.b-water2]=1; que[tail].num=5; que[tail].a=now.a+water2; que[tail].b=now.b-water2; que[tail++].pre=&que[head]; } head++; } step++; } printf("impossible\n");}int main (){ scanf("%d%d%d",&A,&B,&C); memset(vis,0,sizeof(vis)); vis[0][0]=1; BFS(); return 0;}