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 ...
随机推荐
- string.Join和Reverse的简单使用示例
String.Join 方法 (String, String[]) 串联字符串数组的所有元素,其中在每个元素之间使用指定的分隔符. 例如,如果 separator 为“,”且 value 的元素为“a ...
- sql 作业+游标 自动备份数据库
前言 昨天有个同事在客户的服务器上面弄数据库,不小心执行了一条 sql 语句 TRUNCATE TABLE xxx 碉堡了吧,数据全没了 - - ,然后就是在网上拼命的搜索关于数据恢复的软件,搞了一 ...
- Struts2 单个文件上传/多文件上传
1导入struts2-blank.war所有jar包:\struts-2.3.4\apps\struts2-blank.war 单个文件上传 upload.jsp <s:form action= ...
- Linux命令:chmod命令
chmod命令:改变文件或目录的存取权限 #权限代号 -r 文件被读取 4 -w 文件被写入 2 -x 文件被执行 1 #权限范围 -u 文件所有者 -g 文件所有者所在组 -o 其他 -a 全部 # ...
- SGU 128.Snake
时间限制:0.25s 空间限制:4m 题意: 在一个平面坐标中有N个点,现在要你用这N个点构造一个闭合图形,这个图形要满足以下条件: 1.这个图形要是闭合的: 2.图形上的点只能是给 ...
- underscorejs-toArray学习
2.23 toArray 2.23.1 语法: _.toArray(list) 2.23.2 说明: 把list(任何可以迭代的对象)转换成一个数组,在转换arguments对象时非常有用. 2.23 ...
- C#遍历窗体控件(原文出自http://www.liangshunet.com/ca/201403/286434593.htm)
一.C#遍历窗体控件 主要遍历属于窗体(Form)的控件(Controls),假如窗体中有 Panel.Button 和 TextBox 控件,遍历代码如下: /// <summary> ...
- 关于css中透明度继承的问题
今天工作中发现了一个问题,透明度的继承问题,如下图所示: 容器div2就“继承了”外面容器div1的透明度,也变成了70%的透明.容器里面的字体颜色和图片都“继承”了div1,具体代码如下: 可是设计 ...
- PHP表单
二.PHP表单 1.PHP表单处理 welcome.html <html> <body> <form action="welcome.php" met ...
- Html5的<button>标签
1.标签是双标签,其内可添加文字,图片等复杂的样式. 2.不仅可以在表单中使用,还可以在其他块元素和内联元素中使用. 3.一般在input标签内添加name属性,否则提交后不显示.