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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- Android监听ScrollView滑动到顶端和底部
Android监听ScrollView滑动到顶端和底部 package cn.testscrollview; import android.os.Bundle; import android. ...
- Gradle Import Wizard--官方文档
Last updated and checked to work with version 3.0.0 of the tools This tutorial will take you through ...
- [转] boost::function用法详解
http://blog.csdn.net/benny5609/article/details/2324474 要开始使用 Boost.Function, 就要包含头文件 "boost/fun ...
- 网络环境场景以及模拟工具netem
网络环境场景包括: 延迟(Lag),把数据包缓存一段时间后再发出,这样能够模拟网络延迟的状况. 掉包(Drop),随机丢弃一些数据. 节流(Throttle),把一小段时间内的数据拦截下来后再在之后的 ...
- [转] Linux中gcc,g++常用编译选项
http://blog.sina.com.cn/s/blog_5ff2a8a201011ro8.html gcc/g++ 在执行编译时,需要4步 1.预处理,生成.i的文件[使用-E参数] 2.将预处 ...
- Tomcat中Listener的使用范例(转载http://cywhoyi.iteye.com/blog/2075848)
Tomcat是非常有名的开源容器,因其开源我们可以对其做定制化的改变,而且Tomcat在其配置文件方面做了很多注释说明摘要,帮助我们更好的定制化我们所需的功能点. New Tomcat Listene ...
- Android -- 利用Broadcast开启Service(转)
Broadcast和Service都是Android四大组建之一的. 这里的广播是动态的,自己注册的一个广播. 这种最典型的用法就是利用开机广播,然后再起自己的服务,也就是在Android手机中做到开 ...
- 工厂模式[3] 抽象工厂 Abstract Factory
简介 1.简单工厂,或静态工厂,产品接口 定义:专门定义一个类来负责创建其他类的实例,被创建的实例通常具有共同的父类或实现同一接口 优点:客户端可以直接消费产品,而不必关心具体产品的实现(不关心对象的 ...
- javascript innerHTML、outerHTML、innerText、outerText的区别
1.功能讲解: innerHTML 设置或获取位于对象起始和结束标签内的 HTML outerHTML 设置或获取对象及其内容的 HTML 形式 innerText 设置或获取位于对象起始和结束标签内 ...
- hibernate_validator_06
认证组(校验组) 校验组能够让你在验证的时候选择应用哪些约束条件. 这样在某些情况下( 例如向导 ) 就可以对每一步进行校验的时候, 选取对应这步的那些约束条件进行验证了. 校验组是通过可变参数传递给 ...