H - Pots
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
using namespace std; #define maxn 110 int A, B, C;
char a[][] ={ "FILL(1)","FILL(2)","DROP(1)","DROP(2)","POUR(1,2)","POUR(2,1)"}; struct node
{
int fromX, fromY, step, op;
}v[maxn][maxn];
struct point
{
int x, y;
};//当前瓶子A,B的水量 //输出路径
void DFS(int x, int y)
{
if(x == && y == )
return ; DFS(v[x][y].fromX, v[x][y].fromY); printf("%s\n", a[ v[x][y].op ]); }
void BFS()
{
queue<point> Q;
point s, q;
s.x = s.y = ;
v[][].step = ; Q.push(s); while(Q.size())
{
s = Q.front();Q.pop(); if(s.x == C || s.y == C)
{
printf("%d\n", v[s.x][s.y].step-);
DFS(s.x, s.y); return ;
} for(int i=; i<; i++)
{
q = s; if(i == )
q.x = A;
else if(i == )
q.y = B;
else if(i == )
q.x = ;
else if(i == )
q.y = ;
else if(i == )
{
if(q.x+q.y <= B)
q.y += q.x, q.x = ;//把A里面的水全倒B里面
else
q.x -= (B-q.y), q.y = B;//把B倒满
}
else
{
if(q.x+q.y <= A)
q.x += q.y, q.y = ;
else
q.y -= (A-q.x), q.x = A;
} if(v[q.x][q.y].step == )
{
v[q.x][q.y].step = v[s.x][s.y].step+;
v[q.x][q.y].fromX = s.x;
v[q.x][q.y].fromY = s.y;
v[q.x][q.y].op = i; Q.push(q);
}
}
} printf("impossible\n");
} int main()
{
while(scanf("%d%d%d", &A, &B, &C) != EOF)
{
memset(v, , sizeof(v)); BFS();
} return ;
}
H - Pots的更多相关文章
- (poj)3414 Pots (输出路径的广搜)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- Pots(bfs)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8266 Accepted: 3507 Special Judge D ...
- poj 3414 Pots (bfs+线索)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10071 Accepted: 4237 Special J ...
- M - Pots
You are given two pots, having the volume of A and B liters respectively. The following operations c ...
- POJ3414—Pots(bfs加回溯)
http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memor ...
- POJ 3414 Pots(BFS+回溯)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11705 Accepted: 4956 Special J ...
- poj 3414 Pots【bfs+回溯路径 正向输出】
题目地址:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- poj3414 Pots (BFS)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12198 Accepted: 5147 Special J ...
随机推荐
- Dictionary 总结
foreach (KeyValuePair<int, string> kvp in myDictionary) {...} Dictionary<string, string> ...
- Angularjs总结(六) 上传附件
所用插件:angular-file-upload 这个插件用到的几个指令:nv-file-select(点击选择).uploader(用于绑定控制器中新建的uploader对象) HTML: < ...
- Xcode断点的一些黑魔法
转自 只会左键断点?是时候试试这样那样断点了 编码不能没调试,调试不能没断点(Break Point).XCode的断点功能也是越来越强大. 基本断点 如下图,这种是最常用的断点,也是最容易设置.左键 ...
- 【BZOJ1483】【链表启发式合并】梦幻布丁
Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. Input 第 ...
- PowerDesigner 的7种建模文件
1. 概念数据模型 (CDM) 对数据和信息进行建模,利用实体-关系图(E-R图)的形式组织数据,检验数据设计的有效性和合理性. 2. 逻辑数据模型 (LDM) PowerDesigner 15 ...
- javascript删除目标div tr 等
var delTr = document.getElementById("要删除的位置"); // 获取要删除的位置”对象“ delTr.parentNode.removeChil ...
- Magento 编译 php5.6.21 命令
./configure '--prefix=/alidata/server/php' '--enable-opcache' '--with-config-file-path=/alidata/ser ...
- ARM的BIN文件反汇编方法
最近在调试uboot的代码时,用的新版本的uboot,lowlevel_init函数里是空的,而且在链接文件中也没有发现对lowlevel_init.o的链接.在bl lowlevel_init 之前 ...
- 《C++程序设计》上半部读书笔记
目录 前言 第一章 C++的初步知识 1 C语言的优点 2 C++产生的背景 3 C++对C的增强 4 如何体会C++的优点 ...
- PowerShell使用SMTP发送邮件
$smtpServer = "smtp.exmail.qq.com" $smtpUser = "xxxxx@qq.com" $smtpPassword = &q ...