http://poj.org/problem?id=3414

 #include<cstdio>
#include<cstring>
#define MAXN 1000000
using namespace std; int c,d,e,ans,l;
bool vis[][];
struct node
{
int a,b;
int flag;
int pre;
int step;
}p[MAXN],st,st1; void bfs()
{
p[].a=;
p[].b=;
p[].flag=;
p[].step=;
int s=,r=;
vis[][]=true;
while(s<r)
{
st=p[s];
if(st.a==e||st.b==e){ans=st.step;l=s; return;}
if(st.a!=c){
st1.a=c; st1.b=st.b; st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
if(st.b!=d){
st1.a=st.a; st1.b=d; st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
if(st.b!=)
{
if(st.b>=c-st.a){st1.b=st.b-(c-st.a);st1.a=c;}
else {st1.a=st.a+st.b;st1.b=;}
st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
if(st.a!=)
{
if(st.a>=d-st.b){st1.a=st.a-(d-st.b);st1.b=d;}
else {st1.b=st.b+st.a;st1.a=;}
st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
if(st.a!=){
st1.a=; st1.b=st.b; st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
if(st.b!=){
st1.a=st.a; st1.b=; st1.step=st.step+;
st1.pre=s; st1.flag=;
if(!vis[st1.a][st1.b]){
vis[st1.a][st1.b]=true;
p[r++]=st1;
}
}
s++;
}
} void prin(int k)
{
if(k==)
{
return ;
}
prin(p[k].pre);
if(p[k].flag==) printf("FILL(1)\n");
else if(p[k].flag==) printf("FILL(2)\n");
else if(p[k].flag==) printf("POUR(2,1)\n");
else if(p[k].flag==) printf("POUR(1,2)\n");
else if(p[k].flag==) printf("DROP(1)\n");
else if(p[k].flag==) printf("DROP(2)\n");
}
int main()
{
while(scanf("%d%d%d",&c,&d,&e)!=EOF){
ans=;
memset(vis,false,sizeof(vis));
bfs();
if(ans!=){
printf("%d\n",ans);
prin(l);
}
else printf("impossible\n");
}
return ;
}

pojPots的更多相关文章

随机推荐

  1. Linux散列表(二)——宏

    散列表宏承接了双向链表宏的风范,好使好用!务必区分“结点”和“元素”!双链表宏博文中已经提及,这里不赘述! 1.获取元素(结构体)基址 #define hlist_entry(ptr, type, m ...

  2. android使用bintray发布aar到jcenter

    前言 这两天心血来潮突然想把自己的android library的aar放到jcenter里面,这样一来自己便可以在任何时间任何地点通过internet得到自己的library的引用了,况且现在and ...

  3. HDU 4628 多校第三场1008 dp

    这题就没什么好说的了.直接枚举2 ^ 16 的状态,用1表示拿这位,0表示不拿,每次判断是否可以这么拿. #include <iostream> #include <cstdio&g ...

  4. C# Eval在aspx页面中的用法及作用

    Eval( " ")和Bind( " ") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持 ASP.NET 2.0改善了模板中的数据绑定操 ...

  5. 【转】Android Studio中Git的配置及协同开发

    一. Android Stutio配置git   setting–>Version Control–>Git–>Path to Git executable中选择git.exe的位置 ...

  6. Creating a Background Service ——IntentService

    The IntentService class provides a straightforward structure for running an operation on a single ba ...

  7. Python开发【第一篇】:目录

    本系列博文包含 Python基础.前端开发.Web框架.缓存以及队列等,希望可以给正在学习编程的童鞋提供一点帮助!!! Python开发[第一篇]:目录 Python开发[第二篇]:初识Python ...

  8. ASP.NET面试

    1.net中读写数据库需要用到那些类?他们的作用都是什么?答:DataSet:数据存储器.DataCommand:执行语句命令.DataAdapter:数据的集合,用语填充.2.介绍一下什么是Code ...

  9. Directive Definition Object

    不知道为什么这个我并没有想翻译过来的欲望,或许我并没有都看熟透,不好误人子弟,原版奉上. Here's an example directive declared with a Directive D ...

  10. "javascript:void(0)"用法

    1.window.open(''url'') 2.用自定义函数 <script> function openWin(tag,obj) { obj.target="_blank&q ...