Pots POJ 3414
/*
*POJ 3414
*简单模板bfs
*编程应该为了方便理解,尽量提供接口
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=1e2+10;
int VA,VB,VC;
bool inq[maxn][maxn];
vector<int>vec;
struct Node{
int a,b,step;//a,b的值,以及步数
vector<int>ope;
Node(){}
Node(int _a,int _b,int _s){
a=_a;
b=_b;
step=_s;
}
};
void fill(int index,int &A,int &B){
if(index==1) A=VA;
else if(index==2) B=VB;
else printf("Illegal operation!\n");
}
void drop(int index,int &A,int &B){
if(index==1) A=0;
else if(index==2) B=0;
else printf("Illegal operation!\n");
}
void pour(int in1,int in2,int &A,int &B){
if(in1==1&&in2==2){
if(A+B>=VB){
A=A+B-VB;
B=VB;
}
else{
B=A+B;
A=0;
}
}
else if(in1==2&&in2==1){
if(A+B>VA){
B=A+B-VA;
A=VA;
}
else{
A=A+B;
B=0;
}
}
}
Node BFS(){
memset(inq,false,sizeof(inq));
queue<Node>que;
que.push(Node(0,0,0));
inq[0][0]=true;
while(!que.empty()){
Node now=que.front();
que.pop();
int a=now.a,b=now.b,step=now.step;
if(a==VC||b==VC) return now;
for(int i=0;i<6;i++){
int tempa=a,tempb=b;
if(i==0) fill(1,tempa,tempb);
else if(i==1) fill(2,tempa,tempb);
else if(i==2) drop(1,tempa,tempb);
else if(i==3) drop(2,tempa,tempb);
else if(i==4) pour(1,2,tempa,tempb);
else if(i==5) pour(2,1,tempa,tempb);
if(inq[tempa][tempb]==false){
Node next=Node(tempa,tempb,step+1);
next.ope=now.ope;
next.ope.push_back(i);
que.push(next);
inq[tempa][tempb]=true;
}
}
}
return Node(-1,-1,-1);
}
int main(){
scanf("%d%d%d",&VA,&VB,&VC);
Node ans=BFS();
if(ans.a==-1) printf("impossible\n");
else{
printf("%d\n",ans.step);
for(int i=0;i<ans.ope.size();i++){
if(ans.ope[i]==0) printf("FILL(1)\n");
else if(ans.ope[i]==1) printf("FILL(2)\n");
else if(ans.ope[i]==2) printf("DROP(1)\n");
else if(ans.ope[i]==3) printf("DROP(2)\n");
else if(ans.ope[i]==4) printf("POUR(1,2)\n");
else if(ans.ope[i]==5) printf("POUR(2,1)\n");
}
}
return 0;
}
Pots POJ 3414的更多相关文章
- Pots(POJ - 3414)【BFS 寻找最短路+路径输出】
Pots(POJ - 3414) 题目链接 算法 BFS 1.这道题问的是给你两个体积分别为A和B的容器,你对它们有三种操作,一种是装满其中一个瓶子,另一种是把其中一个瓶子的水都倒掉,还有一种就是把其 ...
- Pots POJ - 3414 (搜索+记录路径)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22688 Accepted: 9626 Special J ...
- kuangbin专题 专题一 简单搜索 Pots POJ - 3414
题目链接:https://vjudge.net/problem/POJ-3414 题意:给你两个杯子,分别容量为A(1),B(2)和一个C,C是需要经过下列操作,得到的一个升数.(1) FILL(i) ...
- Pots POJ - 3414【状态转移bfs+回溯】
典型的倒水问题: 即把两个水杯的每种状态视为bfs图中的点,如果两种状态可以转化,即可认为二者之间可以连一条边. 有3种倒水的方法,对应2个杯子,共有6种可能的状态转移方式.即相当于图中想走的方法有6 ...
- POJ 3414 Pots
Pots Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 广搜+输出路径 POJ 3414 Pots
POJ 3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13547 Accepted: 5718 ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
- poj 3414 Pots 【BFS+记录路径 】
//yy:昨天看着这题突然有点懵,不知道怎么记录路径,然后交给房教了,,,然后默默去写另一个bfs,想清楚思路后花了半小时写了120+行的代码然后出现奇葩的CE,看完FAQ改了之后又WA了.然后第一次 ...
- BFS POJ 3414 Pots
题目传送门 /* BFS:六种情况讨论一下,BFS轻松解决 起初我看有人用DFS,我写了一遍,TLE..还是用BFS,结果特判时出错,逗了好长时间 看别人的代码简直是受罪,还好自己终于发现自己代码的小 ...
随机推荐
- 【数据结构】10.java源码关于LinkedHashMap
目录 1.LinkedHashMap的内部结构 2.LinkedHashMap构造函数 3.元素新增策略 4.元素删除 5.元素修改和查找 6.特殊操作 7.扩容 8.总结 1.LinkedHashM ...
- NLP(十二)指代消解
代词是用来代替重复出现的名词 例句: 1.Ravi is a boy. He often donates money to the poor. 先出现主语,后出现代词,所以流动的方向从左到右,这类句子 ...
- 2019牛客暑期多校训练营(第二场) - J - Go on Strike! - 前缀和预处理
题目链接:https://ac.nowcoder.com/acm/contest/882/C 来自:山东大学FST_stay_night的的题解,加入一些注释帮助理解神仙代码. 好像题解被套了一次又一 ...
- P1640 [SCOI2010]连续攻击游戏 二分图构造
https://www.luogu.org/problemnew/show/P1640 题意 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10 ...
- POJ-3261-Milk Patterns-二分+哈希
Milk Patterns 题意: 在一串数字中,求至少连续k次的最大子序列长度: 思路: 二分加哈希: #include <cstdio> #include <iostream&g ...
- CodeForces 980 C Posterized
Posterized 题意:将[0,255] 分成 若干段, 每一段的长度最多为k, 每一个数只能被放进一个段里, 然后每一段的数组都可以被这一段最小的数字表示, 求最小的字典序. 题解:每次一个访问 ...
- hdu2082 找单词 母函数模板
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- ASP.NET CORE Docker发布记录
1.安装Docker yum install curl -y curl -fsSL https://get.docker.com/ | sh 2.编写Dockerfile文件 FROM microso ...
- 如何将 JavaScript 代码添加到网页中,以及 <script> 标签的属性
Hello, world! 本教程的这一部分内容是关于 JavaScript 语言本身的. 但是,我们需要一个工作环境来运行我们的脚本,由于本教程是在线的,所以浏览器是一个不错的选择.我们会尽可能少地 ...
- [1]尝试用Unity3d制作一个王者荣耀(持续更新)->AssetBundle管理器
如果已经看过本章节:目录传送门:这是目录鸭~ 1.AssetBundleManager: 首先我们创建一个文件夹,叫AssetBundleManager,再创建Csharp(即C#)脚本,名为Asse ...