题意:通过题目给出的三种操作,让任意一个杯子中的水到达一定量

分析:两个杯子最大容量是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搜素的更多相关文章

  1. POJ-3414.Pots.(BFS + 路径打印)

    这道题做了很长时间,一开始上课的时候手写代码,所以想到了很多细节,但是创客手打代码的时候由于疏忽又未将pair赋初值,导致一直输出错误,以后自己写代码可以专心一点,可能会在宿舍图书馆或者Myhome, ...

  2. POJ3414—Pots(bfs加回溯)

    http://poj.org/problem?id=3414                                       Pots Time Limit: 1000MS   Memor ...

  3. POJ3414 Pots —— BFS + 模拟

    题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  4. HDU 1226 超级密码 (搜素)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226 题意简单,本来是一道很简单的搜素题目. 但是有两个bug: 1.M个整数可能有重复的. 2.N可 ...

  5. POJ 3414 Pots (BFS/DFS)

    Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7783   Accepted: 3261   Special Ju ...

  6. 开源搜素引擎:Lucene、Solr、Elasticsearch、Sphinx优劣势比较

    https://blog.csdn.net/belalds/article/details/82667692 开源搜索引擎分类 1.Lucene系搜索引擎,java开发,包括: Lucene Solr ...

  7. ACM__搜素之BFS与DFS

    BFS(Breadth_First_Search) DFS(Depth_First_Search) 拿图来说 BFS过程,以1为根节点,1与2,3相连,找到了2,3,继续搜2,2与4,相连,找到了4, ...

  8. POJ-3414 Pots (BFS)

    Description You are given two pots, having the volume of A and B liters respectively. The following ...

  9. poj3414 Pots (BFS)

    Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12198   Accepted: 5147   Special J ...

随机推荐

  1. webx学习笔记

    Webx学习笔记周建旭 2014-08-01 Webx工作流程 图 3.2. Webx Framework如何响应请求 当Webx Framework接收到一个来自WEB的请求以后,实际上它主要做了两 ...

  2. storm sum aggregate 原语 聚合 本地测试

    编写storm程序,对数据进行聚合并且写入到mysql, 本文  主要说明数据中有多个字段需要进行sum或其他操作时的程序写法 1.主程序main方法,storm 拓扑运行入口 public clas ...

  3. redis 在windows 上的安装与使用

    1.redis-windows 最近在做一个抢拍模块,由于过于平凡的insert与update I/O受不了,故只好把东西放内存里,等拍卖结束了,在写入磁盘. 至于为什么要用window呢? 因为服务 ...

  4. Usermod 命令详解

    参考资料:usermod manpage usermod - 修改用户帐户信息 modify a user account usermod [options] user_name usermod 命令 ...

  5. *[topcoder]JumpFurther

    http://community.topcoder.com/stat?c=problem_statement&pm=12300&rd=15699 题意:有一个无限长的阶梯,i从1到N, ...

  6. dynamic_cast 用法

    dynamic_cast < type-id > ( expression ) 该运算符把expression转换成type-id类型的对象.Type-id必须是类的指针.类的引用或者vo ...

  7. HDU1875——畅通工程再续(最小生成树:Kruskal算法)

    畅通工程再续 Description相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现.现在政府决定大力发展百岛湖,发展首先要解决的问题当 ...

  8. Armitage初始化

    Kali2.0 Armitage初始化步骤如下 (1)点击页面的Armitage按钮 (2)提示Metasploit RPC server is not running,是否启动该服务,选择是 (3) ...

  9. php修改排序,上移下移

    php修改排序,上移下移 /**    $UpDown //移动方向,up或down    $table //表名    $id //当前移动的ID    $id_col //ID字段的名称    $ ...

  10. default parameter value for ‘color’ must be a compile-time constant

    定义了一个函数,函数有一个参数是Color类型的可选参数,想要设置其默认值为Color.Black http://stackoverflow.com/questions/2804395/c-sharp ...