BFS POJ 3414 Pots
/*
BFS:六种情况讨论一下,BFS轻松解决
起初我看有人用DFS,我写了一遍,TLE。。还是用BFS,结果特判时出错,逗了好长时间
看别人的代码简直是受罪,还好自己终于发现自己代码的小错误:)
*/
/************************************************
Author :Running_Time
Created Time :2015-8-3 14:17:24
File Name :POJ_3414_BFS.cpp
**************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
struct Point {
int a, b, step;
int op[MAXN];
};
bool vis[][];
int A, B, C;
int ans; void BFS(void) {
memset (vis, false, sizeof (vis));
queue<Point> Q; Q.push ((Point) {, , });
while (!Q.empty ()) {
Point p = Q.front (); Q.pop ();
if (p.a == C || p.b == C) {
printf ("%d\n", p.step);
for (int i=; i<=p.step; ++i) {
if (p.op[i] == ) puts ("FILL(1)");
else if (p.op[i] == ) puts ("FILL(2)");
else if (p.op[i] == ) puts ("DROP(1)");
else if (p.op[i] == ) puts ("DROP(2)");
else if (p.op[i] == ) puts ("POUR(1,2)");
else if (p.op[i] == ) puts ("POUR(2,1)");
}
return ;
}
Point tmp;
if (p.a < A && !vis[A][p.b]) {
vis[A][p.b] = true;
tmp = p; tmp.a = A; tmp.op[++tmp.step] = ; //FILL1
Q.push (tmp);
}
if (p.b < B && !vis[p.a][B]) {
vis[p.a][B] = true;
tmp = p; tmp.b = B; tmp.op[++tmp.step] = ; //FILL2
Q.push (tmp);
}
if (p.a > && !vis[][p.b]) {
vis[][p.b] = true;
tmp = p; tmp.a = ; tmp.op[++tmp.step] = ; //DROP1
Q.push (tmp);
}
if (p.b > && !vis[p.a][]) {
vis[p.a][] = true;
tmp = p; tmp.b = ; tmp.op[++tmp.step] = ; //DROP2
Q.push (tmp);
}
if (p.a > && p.b < B) {
int t = min (p.a, B - p.b);
if (!vis[p.a-t][p.b+t]) {
vis[p.a-t][p.b+t] = true; //POUR1->2
tmp = p; tmp.a -= t; tmp.b += t; tmp.op[++tmp.step] = ;
Q.push (tmp);
}
}
if (p.b > && p.a < A) {
int t = min (p.b, A - p.a);
if (!vis[p.a+t][p.b-t]) {
vis[p.a+t][p.b-t] = true; //POUR2->1
tmp = p; tmp.a += t; tmp.b -= t; tmp.op[++tmp.step] = ;
Q.push (tmp);
}
}
} puts ("impossible");
} int main(void) { //POJ 3414 Pots
while (scanf ("%d%d%d", &A, &B, &C) == ) {
BFS ();
} return ;
}
BFS POJ 3414 Pots的更多相关文章
- poj 3414 Pots 【BFS+记录路径 】
//yy:昨天看着这题突然有点懵,不知道怎么记录路径,然后交给房教了,,,然后默默去写另一个bfs,想清楚思路后花了半小时写了120+行的代码然后出现奇葩的CE,看完FAQ改了之后又WA了.然后第一次 ...
- 广搜+输出路径 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+回溯路径 正向输出】
题目地址:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3414 Pots
Pots Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 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://blog.csdn.net/u012860063?viewmode=contents 题目链接:id=3414">http://poj.org/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 很好玩的一个题.关键是又16ms 1A了,没有debug的日子才是好日子.. #include <stdio.h> # ...
随机推荐
- android framework navigationbar自定义
需要实现的目标:在navigationbar上显示录像预览,并且点击按钮可以显示/隐藏NavigationBar 参考文章: http://blog.csdn.net/yanlai20/article ...
- [bzoj3513][MUTC2013]idiots_FFT
idiots bzoj-3513 MUTC-2013 题目大意:给定$n$根木棍,问随机选择三根能构成三角形的概率. 注释:$1\le n\le 3\cdot 10^5$,$1\le a_i\le 1 ...
- Ubuntu 16.04安装Intel显卡驱动(解决Intel HD Graphics 630显卡驱动问题)
一般Ubuntu都默认包含了Intel显卡的驱动,如果没有,那么先确定是不是显卡太高,比如I7第7代的CPU核显在Ubuntu 16.04中是没有的,导致画面会很卡,原因是Linux 4.4内核不包含 ...
- Ubuntu 16.04下搭建基于携程Apollo(阿波罗)配置中心单机模式
官网:https://github.com/ctripcorp/apollo Wiki:https://github.com/ctripcorp/apollo/wiki(一切的集成方式和使用方法都在这 ...
- JAVA程序—HelloWorld 的编译运行
在我们写好我们的"HelloWorld.java",并且搭建好JAVA的开发环境过后,便可以运行这个JAVA程序了. 具体如何实现,让我们来看看: 打开DOS 通过DOS命令转到& ...
- 1072. Gas Station (30)【最短路dijkstra】——PAT (Advanced Level) Practise
题目信息 1072. Gas Station (30) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B A gas station has to be built at s ...
- C# VS如何整个项目中查找字符串
Ctrl+F打开查找对话框,然后输入查找字符串,电机右边的小三角,选择整个解决方案,就可以遍历所有文件查找指定字符了
- Vue.js 组件的三个 API:prop、event、slot
组件的构成 一个再复杂的组件,都是由三部分组成的:prop.event.slot,它们构成了 Vue.js 组件的 API.如果你开发的是一个通用组件,那一定要事先设计好这三部分,因为组件一旦发布,后 ...
- Android自己定义组件系列【5】——进阶实践(2)
上一篇<Android自己定义组件系列[5]--进阶实践(1)>中对任老师的<可下拉的PinnedHeaderExpandableListView的实现>前一部分进行了实现,这 ...
- Python开发【第*篇】【Xpath与lxml类库】
什么是XML XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML 的设计宗旨是传输数据,而非显示数据 XML 的标签需要 ...