POJ 3414 Pots 暴力,bfs 难度:1
http://poj.org/problem?id=3414
记录瓶子状态,广度优先搜索即可
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=101;
int n,m;
typedef unsigned long long ull;
int A,B,C;
int vis[maxn][maxn];
int ans[maxn][maxn][maxn*maxn];
struct node{
int a,b;
node (int ta,int tb):a(ta),b(tb){}
};
void printop(int op){
switch(op){
case 0:
puts("FILL(1)");
break;
case 1:
puts("FILL(2)");
break;
case 2:
puts("POUR(1,2)");
break;
case 3:
puts("POUR(2,1)");
break;
case 4:
puts("DROP(1)");
break;
case 5:
puts("DROP(2)");
break;
}
}
void op(int &a,int &b,int op){
switch(op){
case 0:
a=A;
break;
case 1:
b=B;
break;
case 2:
if(b+a<=B){
b+=a;
a=0;
}
else {
a-=B-b;
b=B;
}
break;
case 3:
if(b+a<=A){
a+=b;
b=0;
}
else {
b-=A-a;
a=A;
}
break;
case 4:
a=0;
break;
case 5:
b=0;
break;
}
}
void bfs(){
queue <node> que;
que.push(node(0,0));
vis[0][0]=0;
while(!que.empty()){
node tp=que.front();que.pop();
int ta=tp.a;
int tb=tp.b;
if(tp.a==C||tp.b==C){
printf("%d\n",vis[tp.a][tp.b]);
for(int i=0;i<vis[ta][tb];i++){
int op=ans[ta][tb][i];
printop(op);
}
return ;
}
for(int i=0;i<6;i++){
int ta=tp.a;
int tb=tp.b;
op(ta,tb,i);
if(vis[ta][tb]==-1){
vis[ta][tb]=vis[tp.a][tp.b]+1;
for(int j=0;j<vis[tp.a][tp.b];j++){
ans[ta][tb][j]=ans[tp.a][tp.b][j];
}
ans[ta][tb][vis[tp.a][tp.b]]=i;
que.push(node(ta,tb));
}
}
}
puts("impossible");
}
int main(){
scanf("%d%d%d",&A,&B,&C);
memset(vis,-1,sizeof(vis));
bfs();
return 0;
}
POJ 3414 Pots 暴力,bfs 难度:1的更多相关文章
- poj 3414 Pots 【BFS+记录路径 】
//yy:昨天看着这题突然有点懵,不知道怎么记录路径,然后交给房教了,,,然后默默去写另一个bfs,想清楚思路后花了半小时写了120+行的代码然后出现奇葩的CE,看完FAQ改了之后又WA了.然后第一次 ...
- poj 3414 Pots【bfs+回溯路径 正向输出】
题目地址:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 3414 Pots ( bfs )
题目:http://poj.org/problem?id=3414 题意:给出了两个瓶子的容量A,B, 以及一个目标水量C, 对A.B可以有如下操作: FILL(i) fill the ...
- POJ - 3414 Pots 【BFS】
题目链接 http://poj.org/problem?id=3414 题意 给出两个杯子 容量分别为 A B 然后给出C 是目标容量 有三种操作 1 将一个杯子装满 2.将一个杯子全都倒掉 3.将一 ...
- poj 3414 Pots (bfs+线索)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10071 Accepted: 4237 Special J ...
- (简单) POJ 3414 Pots,BFS+记录路径。
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- POJ 3414 Pots(BFS+回溯)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11705 Accepted: 4956 Special J ...
- BFS POJ 3414 Pots
题目传送门 /* BFS:六种情况讨论一下,BFS轻松解决 起初我看有人用DFS,我写了一遍,TLE..还是用BFS,结果特判时出错,逗了好长时间 看别人的代码简直是受罪,还好自己终于发现自己代码的小 ...
随机推荐
- python调用C++之pybind11入门(相互调用)
python调用C/C++有不少的方法,如boost.python, swig, ctypes, pybind11等,这些方法有繁有简,而pybind11的优点是对C++ 11支持很好,API比较简单 ...
- 比特币BTC全节点搭建
比特币BTC全节点搭建 #环境 ubuntu 16.4 #硬盘500GB #截止2018-12-31磁盘占用超过230GB #客户端安装 #下载页面 #https://bitcoin.org/zh_C ...
- Jetty:配置概览-怎么配置Jetty
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/liuy_98_1001/article/details/27544671 Jetty POJO配置 ...
- Log表新的RowKey设计,预Split
1 目前Rawlog表的问题 region数量庞大,空region 率大 共有12791个region 11409空region, 比例为89.19% 剩余的region大小也是极度不均衡,最大的re ...
- Struct2小结:
Action小结: 实现一个Action的最常用的方式:从ActionSupport继承: DMI动态方法调用,减少配置内容: 通配符 *_* ({1},{2})的使用更方便: 接收参数的方法(一般用 ...
- weiwo.wxmmd.com将您重定向的次数过多。尝试清除 Cookie.
折腾了很久,最后更换PHP版本解决了,我的项目用的tp3.1.2,出现上图问题时的php版本是7.1,换回5.6就没有这个问题.希望能为大家提供一个思路.
- Linux /proc/pid目录下各文件含义
/proc 是一个伪文件系统, 被用作内核数据结构的接口, 而不仅仅是解释说明/dev/kmem. /proc 里的大多数文件都是只读的, 但也可以通过写一些文件来改变内核变量. ( Linux 内核 ...
- cas php
CAS的php客户端实践—单点登录整合php程序 兄弟近日尝试将一个php程序以单点登录方式和原有的系统整合在一起.验证服务器选用的是CAS,其提供有相应的php客户端.整个过程如下:1.搭建CAS服 ...
- linux下高并发网络应用注意事项
本文转自:http://www.blogjava.net/bacoo/archive/2012/06/11/380500.html linux下高并发网络应用注意事项 vi /etc/sysctl.c ...
- SQL学习笔记三(补充-3)之MySQL完整性约束
阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 介绍 约束条件与数据 ...