Description

You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:

  1. FILL(i)        fill the pot i (1 ≤ i ≤ 2) from the tap;
  2. DROP(i)      empty the pot i to the drain;
  3. 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 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) 给你两个壶,容量a,b,让你三种操作 1.接满 2.一个壶倒到另一个壶(这个壶倒空了或者那个壶满了 才停止) 3.把一个壶倒空 问你几步两个壶中能有一个壶容量是能c。
这个题显然bfs,就是node结构体里面在加上一个queue和string保存下之前的状态。没啥了,代码好长啊QAQ。
代码如下:
 #include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
struct node
{
int na,nb,step;
vector<int> num;
string ns;
};
bool vis [][];
int a,b,c;
bool iffind;
void init ()
{
memset(vis,false,sizeof vis);
iffind=false;
}
void bfs(node now)
{
queue<node>q;
q.push(now);
while (!q.empty())
{
node temp=q.front();
q.pop();
if (vis[temp.na][temp.nb])
continue ;
vis[temp.na][temp.nb]=true;
if (temp.na==c||temp.nb==c)//success
{
iffind=true;
printf("%d\n",temp.step);
//printf("=== %d %d\n",sizeof(temp.ns),temp.num.size());
for (int i=;i<temp.num.size();++i)
{
if (temp.ns[i]=='F')
{
printf("FILL");
if (temp.num[i]==)
printf("(1)\n");
else
printf("(2)\n");
}
else if (temp.ns[i]=='P')
{
printf("POUR");
if (temp.num[i]==)
printf("(1,2)\n");
else
printf("(2,1)\n");
}
else
{
printf("DROP");
if (temp.num[i]==)
printf("(1)\n");
else
printf("(2)\n");
}
}
return ;
}
if (temp.na!=a)//fill a
{
node now=temp;
now.step++;
now.na=a;
now.ns+="F";
now.num.push_back();
q.push(now);
}
if (temp.nb!=b)//fill b
{
node now=temp;
now.step++;
now.nb=b;
now.ns+="F";
now.num.push_back();
q.push(now);
}
if (temp.na>&&temp.nb<b)//pour a to b
{
node now=temp;
now.step++;
now.na-=min(temp.na,b-temp.nb);
now.nb+=min(temp.na,b-temp.nb);
now.ns+="P";
now.num.push_back();
q.push(now);
}
if (temp.nb>&&temp.na<a)//pour b to a
{
node now=temp;
now.step++;
now.nb-=min(temp.nb,a-temp.na);
now.na+=min(temp.nb,a-temp.na);
now.ns+="P";
now.num.push_back();
q.push(now);
}
if(temp.na!=)// drop a
{
node now=temp;
now.step++;
now.na=;
now.ns+='D';
now.num.push_back();
q.push(now);
}
if(temp.nb!=)//drop b
{
node now=temp;
now.step++;
now.nb=;
now.ns+='D';
now.num.push_back();
q.push(now);
}
}
return ;
}
int main()
{
while (~scanf("%d%d%d",&a,&b,&c))
{
init();
node x;
x.na=,x.nb=,x.ns="",x.step=,x.num.clear();
bfs(x);
if (iffind==false){
printf("impossible\n");
}
}
return ;
}
 

最新文章

  1. C语言 &#183; 乘法表
  2. Hadoop入门学习笔记---part1
  3. css中单位em和rem
  4. next_permutation 和 一个不成功的案例
  5. DataGridView 控件用法(可能不是很全面,因为这是自己常常用到的一些小总结):
  6. 降低IIScup使用率,提高性能
  7. 得到bundle seed id
  8. 【Linux】鸟哥的Linux私房菜基础学习篇整理(九)
  9. wordpress参考网站
  10. DEV GridControl导出到Excel或打印
  11. 转换器2:ThinkPhp模板转Django模板
  12. CodeForces 242E二维线段树
  13. 前端Web开发MVC模式-入门示例
  14. 标准的SQL语句类型
  15. MySQL8.0.x免安装配置
  16. B/S架构与C/S架构
  17. NPOI 设置样式为粗体
  18. javac编译提示错误需要为 class、interface 或 enum
  19. SED命令用法整理
  20. banner 跟随鼠标呈现视差效果

热门文章

  1. SSM项目用ajax来显示数据
  2. UVA 12012 Detection of Extraterrestrial(KMP求循环节)
  3. 迅捷路由器FW325R的无线桥接
  4. git分支merger
  5. redis.conf 配置文件介绍
  6. html 和 body标签的 css 设置
  7. Ajax二级联动简单实例
  8. javascript获取网页宽高,屏幕宽高,屏幕分辨率等
  9. selenium,webdriver爬取斗鱼主播信息 实操
  10. iis 跨域设置多域名