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 ...
随机推荐
- iOS Icon尺寸、iPhone Ratina 分辨率
高清晰度的iPhone和iPod touch(单位:像素) 启动影像 :640 x 960 APP图标:114 x 114 App Store商店:1024 x 1024 Spotlight搜索小图标 ...
- iOS5编程--ARC在工程上的相关设置
在创建工程的时候,我们可以指定工程是否使用ARC技术,如下图 选中表示支持ARC, 在Beta5以前的版本中,不提供这个选项,非常麻烦. 如果是你拿到的工程,那么可以通过设置来改变,如下图所示 如果不 ...
- [转]oracle10.2.0.1下载链接
记录一下ORACLE 10gR2的软件下载地址,备用. 下载OTN上的这些软件,你需要一个OTN免费帐号,不过如果通过迅雷进行下载,就不用登陆OTN了: Oracle Database 10g Rel ...
- jmeter测试本地myeclips调试状态下的tomcat程序死锁
在myeclipse调试状态下的tomcat程序,用jmeter测试,居然发生死锁,调试两天无果,直接运行tomcat而不通过myeclipse,无死锁,真是又好气又好笑..
- jquery1.8在ie8下not无效?
// 不需要的name加到下面 var excludes = ['name1', 'name2', 'name3']; $.each(excludes, function (i, v) { e ...
- 1056: [HAOI2008]排名系统 - BZOJ
Description 排名系统通常要应付三种请求:上传一条新的得分记录.查询某个玩家的当前排名以及返回某个区段内的排名记录.当某个玩家上传自己最新的得分记录时,他原有的得分记录会被删除.为了减轻服务 ...
- ExtJS4.2学习(13)基于表格的扩展插件---rowEditing
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-24/182.html --------------- ...
- SQLite入门与分析(四)---Page Cache之事务处理(1)
写在前面:从本章开始,将对SQLite的每个模块进行讨论.讨论的顺序按照我阅读SQLite的顺序来进行,由于项目的需要,以及时间关系,不能给出一个完整的计划,但是我会先讨论我认为比较重要的内容.本节讨 ...
- 123. Best Time to Buy and Sell Stock III
题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- POJ3026——Borg Maze(BFS+最小生成树)
Borg Maze DescriptionThe Borg is an immensely powerful race of enhanced humanoids from the delta qua ...