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个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
随机推荐
- .Net动态加载插件-反射
/// <summary> /// 动态加载插件 /// </summary> void LoadPlugin() { string[] ps = Directory.GetF ...
- Swift3.0 更新后出现比较运算符方法
在将项目更新到swift3.0之后,在一些controller头部会出现 比较运算符的方法 // FIXME: comparison operators with optionals were rem ...
- WCF:如何将net.tcp协议寄宿到IIS
1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协议的服务,为了让IIS支持net.tcp,必须先安装WAS(Windows Process Activation Service),即 ...
- ubuntu sublime安装及配置
安装sublime-text-2: sudo add-apt-repository ppa:webupd8team/sublime-text-2 sudo apt-get update sudo ap ...
- Failed dependencies: 检查依赖性错误 解决方法
centOs下: error: Failed dependencies: 检查依赖性错误 解决方法 刚才安装avast的linux版,结果出现了: [root@localhost /]# rpm -i ...
- Nginx反向代理,负载均衡配置
主配置文件:nginx.conf # For more information on configuration, see: # * Official English Documentation: h ...
- Ci 分页类的所有属性总结
//#######################自定义分页 $config['uri_segment'] = 3;//分页方法自动测定你 URI 的哪个部分包含页数 $config['num_lin ...
- Asp.net中的页面跳转及post数据
/// <summary> /// This method prepares an Html form which holds all data /// in hidden field i ...
- asp.net中@page 指令的属性Inherits、Src、CodeBehind区别
在 ASP.NET 中使用代码隐藏方法来设计Web 窗体,可使页代码能够更清晰地从 HTML 内容中分离到完全单独的文件中. <%@ Page language="c#" C ...
- WorkBook的SaveAs方法 2
-----转载:http://blog.csdn.net/zyming0815/article/details/5939104 语法 声明Sub SaveAs ( _ Filename As ...