poj 1606Jugs
http://poj.org/problem?id=1606
#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 A\n");
else if(p[k].flag==) printf("fill B\n");
else if(p[k].flag==) printf("pour B A\n");
else if(p[k].flag==) printf("pour A B\n");
else if(p[k].flag==) printf("empty A\n");
else if(p[k].flag==) printf("empty B\n");
}
int main()
{
while(scanf("%d%d%d",&c,&d,&e)!=EOF){
ans=;
memset(vis,false,sizeof(vis));
bfs();
if(ans!=){
prin(l);
printf("success\n");
}
}
return ;
}
poj 1606Jugs的更多相关文章
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- javaScript的使用
<script>XXX</ccript>HTML文件插入js的主要方法.这个标签主要有以下的几个属性: 1,charset:可选.表示通过src属性指定的字符集. 2,defe ...
- 如何设置jsp默认的编码为utf-8
方法一: 文件里写: <%@ page contentType="text/html; charset=UTF-8" %> 方法二: 选择window –> P ...
- Android开发系列(一)Activity与Fragment获取屏幕获取屏幕像素的不同方式
Activity中常用的获取屏幕像素代码: //获取屏幕像素相关信息 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getD ...
- android中的文件操作详解以及内部存储和外部存储(转载)
原文链接:http://m.blog.csdn.net/article/details?id=17725989 摘要 其实安卓文件的操作和java在pc环境下的操作并无二致,之所以需要单独讲解是因为安 ...
- 通同select便签实现简单的二级联动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- asp.net基础概念总结
1 什么是asp.net?asp.net是一种编程语言吗? asp.net是Microsoft公司推出的新一代建立动态web应用程序的开发平台,是一种建立动态web应用程序的新技术. 不是,asp. ...
- Ext4 简单的treepanel
转载:http://blog.csdn.net/zyujie/article/details/8208499 最近在学习Ext4,记录一些有关Ext4实现控件的方法: Ext4的treePanel和之 ...
- FckEditor组件的使用(新闻浏览发布页面)
FckEditor组件的使用 准备工作: 1)将FckEditor目录拷贝到网站根目录内. 2)在Web.config的AppSetting分支中添加如下的代码,并修改FckEditor的目录和上传文 ...
- iOS开发之四张图说明GCD(Grand Central Dispatch)附Test源码
首先,先介绍几个概念:GCD,队列,串行,并行,同步,异步. ...
- SQL Server附加数据库拒绝访问
打开要附加的数据库文件所在的文件夹,即扩展名为mdf的文件所在的文件夹,如下图所示: 右键单击mdf文件,选择“属性”,如下图所示: 单击“安全”选项卡,如下图所示: 单击“编辑”按钮,如 ...