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. JS常用扩展

    // 清除两边的空格 String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ''); }; // 合并多 ...

  2. Thread Join()的用法

    Java Thread类有个 join() 方法,先前一直不知道是怎么用的,直到看到这篇文章.http://auguslee.iteye.com/blog/1292203 Java Thread中, ...

  3. 【技术文档】《算法设计与分析导论》R.C.T.Lee等·第4章 分治策略

    分治策略有一种“大事化小,小事化了”的境界,它的思想是将原问题分解成两个子问题,两个子问题的性质和原问题相同,因此这两个子问题可以再用分治策略求解,最终将两个子问题的解合并成原问题的解.有时,我们会有 ...

  4. mysql编码和Java编码相应一览表

    MySQL to Java Encoding Name Translations MySQL Character Set Name Java-Style Character Encoding Name ...

  5. spring mvc使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext和XmlWebApplicationContext类的操作其中 XmlWebApplicationContext是专为Web工程定制的。

    一.简单的用ApplicationContext做测试的话,获得Spring中定义的Bean实例(对象).可以用: ApplicationContext ac = new ClassPathXmlAp ...

  6. Java NIO中核心组成和IO区别

    1.Java NIO核心组件 Java NIO中有很多类和组件,包括Channel,Buffer 和 Selector 构成了核心的API.其它组件如Pipe和FileLock是与三个核心组件共同使用 ...

  7. 模板-->中国剩余定理[互质版本]

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 扩展欧几里得extend_gcd模板 poj_1006_Biorhythms,my_ac_code 简单的测试 None ...

  8. document.all用法

    document.all用法 一. document.all是页面内所有元素的一个集合.例如:       document.all(0)表示页面内第一个元素二.document.all可以判断浏览器 ...

  9. Java实现文件上传

    最近自己在做一个小系统玩的时候涉及到了文件的上传,于是在网上找到Java上传文件的方案,最后确定使用common-fileupload实现上传操作. 需求说明 用户添加页面有一个“上传”按钮,点击按钮 ...

  10. 关于电脑开机不出现桌面即不启动explorer.exe桌面程序--------正解

    针对这个问题,一开始的思路是,把自己写的界面小程序(Win.exe)放在Windows启动文件夹中, 效果到是界面程序自启动了,但是还是先出现的桌面,然后才的启动的界面程序(Win.exe),并不是我 ...