POJ3414 Pots BFS搜素
题意:通过题目给出的三种操作,让任意一个杯子中的水到达一定量
分析:两个杯子最大容量是100,所以开个100*100的数组记录状态,最多1w个状态,所以复杂度很低,然后记录一下路径就好
注:代码写残了,我也不会写好看的那种,罪过罪过..QAQ
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stdlib.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;
const int maxn=;
const int INF=0x3f3f3f3f;
struct Point
{
int x,y,op,s;
} mp[maxn][maxn],o,t;
int p[maxn][maxn];
queue<Point>q;
void print(int x,int y)
{
if(x==-)return;
print(mp[x][y].x,mp[x][y].y);
if(mp[x][y].op==)printf("FILL(%d)\n",mp[x][y].s);
else if(mp[x][y].op==)printf("DROP(%d)\n",mp[x][y].s);
else if(mp[x][y].op==)printf("POUR(%d,%d)\n",mp[x][y].s,-mp[x][y].s);
}
int main()
{
int a,b,c,flag=;
scanf("%d%d%d",&a,&b,&c);
for(int i=; i<=a; ++i)
for(int j=; j<=b; ++j)
mp[i][j].op=-;
mp[a][].op=,mp[a][].s=;
mp[][b].op=,mp[][b].s=;
mp[a][].x=-,mp[][b].x=-;
o.x=a,o.y=;
q.push(o);
o.x=,o.y=b;
q.push(o);
p[a][]=p[][b]=;
while(!q.empty())
{
o=q.front();
q.pop();
if(o.x==c||o.y==c)
{
t=o;
flag=;
break;
}
if(o.x<a)
{
if(mp[a][o.y].op==-)
{
mp[a][o.y].op=;
mp[a][o.y].s=;
mp[a][o.y].x=o.x;
mp[a][o.y].y=o.y;
t.x=a,t.y=o.y;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
}
if(o.y<b)
{
if(mp[o.x][b].op==-)
{
mp[o.x][b].op=;
mp[o.x][b].s=;
mp[o.x][b].x=o.x;
mp[o.x][b].y=o.y;
t.x=o.x,t.y=b;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
}
if(o.x)
{
if(mp[][o.y].op==-)
{
mp[][o.y].op=;
mp[][o.y].s=;
mp[][o.y].x=o.x;
mp[][o.y].y=o.y;
t.x=,t.y=o.y;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
int cha=b-o.y;
if(o.x<=cha)
t.y=o.y+o.x,t.x=;
else t.y=b,t.x=o.x-cha;
if(mp[t.x][t.y].op==-)
{
mp[t.x][t.y].op=;
mp[t.x][t.y].s=;
mp[t.x][t.y].x=o.x;
mp[t.x][t.y].y=o.y;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
}
if(o.y)
{
if(mp[o.x][].op==-)
{
mp[o.x][].op=;
mp[o.x][].s=;
mp[o.x][].x=o.x;
mp[o.x][].y=o.y;
t.x=o.x,t.y=;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
int cha=a-o.x;
if(o.y<=cha)
t.x=o.y+o.x,t.y=;
else t.x=a,t.y=o.y-cha;
if(mp[t.x][t.y].op==-)
{
mp[t.x][t.y].op=;
mp[t.x][t.y].s=;
mp[t.x][t.y].x=o.x;
mp[t.x][t.y].y=o.y;
p[t.x][t.y]=p[o.x][o.y]+;
q.push(t);
}
}
}
if(flag)printf("%d\n",p[t.x][t.y]),print(t.x,t.y);
else printf("impossible\n");
return ;
}
POJ3414 Pots BFS搜素的更多相关文章
- POJ-3414.Pots.(BFS + 路径打印)
这道题做了很长时间,一开始上课的时候手写代码,所以想到了很多细节,但是创客手打代码的时候由于疏忽又未将pair赋初值,导致一直输出错误,以后自己写代码可以专心一点,可能会在宿舍图书馆或者Myhome, ...
- POJ3414—Pots(bfs加回溯)
http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memor ...
- POJ3414 Pots —— BFS + 模拟
题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- HDU 1226 超级密码 (搜素)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226 题意简单,本来是一道很简单的搜素题目. 但是有两个bug: 1.M个整数可能有重复的. 2.N可 ...
- POJ 3414 Pots (BFS/DFS)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7783 Accepted: 3261 Special Ju ...
- 开源搜素引擎:Lucene、Solr、Elasticsearch、Sphinx优劣势比较
https://blog.csdn.net/belalds/article/details/82667692 开源搜索引擎分类 1.Lucene系搜索引擎,java开发,包括: Lucene Solr ...
- ACM__搜素之BFS与DFS
BFS(Breadth_First_Search) DFS(Depth_First_Search) 拿图来说 BFS过程,以1为根节点,1与2,3相连,找到了2,3,继续搜2,2与4,相连,找到了4, ...
- POJ-3414 Pots (BFS)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- poj3414 Pots (BFS)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12198 Accepted: 5147 Special J ...
随机推荐
- 【BZOJ 1084】[SCOI2005]最大子矩阵
Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. Input 第一行为n,m,k(1≤n≤100,1≤m≤2 ...
- Nhibernate 多对多级联删除
在网上找到的方法:查看这里 //-------------------------------------Article.hbm.xml-------------------------------- ...
- 3.9 spring-自定义标签解析
到这里,我们已经完成了分析默认标签的解析与提取过程,或许设计的内容太多,我们忘了我们是冲哪个函数开始了的, 让我们再次回顾一下默认标签解析方法的起始方法. 入口如下: /** * Parse the ...
- ANN中Precision-Recall权衡
如果想要得到较高的精度,则需要较长的编码. 编码长度m增长的话,则item碰撞的概率会成倍的减小,从而导致召回率下降. 为了得到较高的召回率,则需要多个哈希表. 参考http://yongyuan.n ...
- js获取fck值的代码方法
引入js文件 <script type="text/javascript" src="${basePath}/FCKeditor/fckeditor.js" ...
- RCC 2014 Warmup (Div. 2) ABC
题目链接 A. Elimination time limit per test:1 secondmemory limit per test:256 megabytesinput:standard in ...
- Spring在代码中获取bean的几种方式
方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...
- C/C++语言参数传递----函数/方法 参数的指针引用传递
int m_value = 1; void func(int *p) { p = &m_value; } int main(int argc, char *argv[]) { int n = ...
- java jdk自带程序分析(内存分析/线程分析)
周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令. 1.1.Jstack 1.1 jstack能得到运行jav ...
- MyBatis的CRUD操作
MyBatis的两个主要配置文件 mytatis.xml:放在src目录下,常见的配置如下 <?xml version="1.0" encoding="UTF-8& ...