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,结果特判时出错,逗了好长时间 看别人的代码简直是受罪,还好自己终于发现自己代码的小 ...
随机推荐
- Kafka集群部署 (守护进程启动)
1.Kafka集群部署 1.1集群部署的基本流程 下载安装包.解压安装包.修改配置文件.分发安装包.启动集群 1.2集群部署的基础环境准备 安装前的准备工作(zk集群已经部署完毕) 关闭防火墙 c ...
- Git 进阶之底层相关
Git is a content-addressable filesystem. 1. Plumbing 和 Porcelain "Plumbing commands": Git ...
- SpringCloud 进阶之分布式配置中心(SpringCloud Config)
1. SpringCloud Config SpringCLoud Config 为微服务架构中的微服务提供集中化的外部配置支持,配置服务器为各个不同微服务应用 的所有环境提供了一个中心化的外部配置; ...
- mysql实现开窗函数、Mysql实现分析函数
关键字:mysql实现开窗函数.Mysql实现分析函数.利用变量实现窗口函数 注意,变量是从左到右顺序执行的 --测试数据 CREATE TABLE `tem` ( `id` ) NOT NULL A ...
- SSL/TSL握手过程详解
1. Client Hello 握手第一步是客户端向服务端发送 Client Hello 消息,这个消息里包含了一个客户端生成的随机数 Random1.客户端支持的加密套件(Support Ciphe ...
- python面向对象编程基础
演示了 Python 类与对象的编程基础, 包括属性.方法.继承.组合.动态创建类. python 版本: 2.7.5 class SimpleClass(object): ''' a simple ...
- linux 常用命令总结(二)
1. linux下以指定的编码打开文件:LANG=zh_CN vi fileName 2. 查看系统内存使用,可以使用free -m 或 top 3. 使用env查看所有环境变量 4. df –h 查 ...
- 异常来自HRESULT:0x80070422
今天同事使用一个用VB.NET2008开发的应用程序时提示“出现了下列应用程序错误:无法启动服务,原因可能是已被禁用或与其相关联的设备没有启动.(异常来自HRESULT:0x80070422)” ...
- Core Java 5
p273~p276: 1.获取异常的更多信息:e.getMessage(). 2.得到异常的实际类型:e.getClass().getName(). 3.当异常之间不存在子类关系,并且异常的处理机制( ...
- P1052 过河(离散化+dp)
P1052 过河 dp不难,重点是要想到离散化. 石子个数$<=100$意味着有大量空间空置,我们可以缩掉这些空间. 实现的话自己yy下就差不多了. #include<iostream&g ...