POJ3414-Pots
来源:互联网 发布:手机淘宝怎么放优惠券 编辑:程序博客网 时间:2024/06/05 21:11
题目链接:http://poj.org/problem?id=3414
给出三个数,分别是第一个杯子的容量,第二个杯子的容量,以及所需的体积。
有三种操作:加水,把水倒掉,把水从一个杯子倒进另一个杯子。
就一个bfs水题。。。真的。
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈劳资终于AC了!!!!!!!!!!!
额。。。认真讲就是保存操作路径的时候不能随便存,我用的模拟队列,记录前一步的in值,从后往前就可以找到路径了。
//220K0MS//C++1581B#include <cstring>#include <cstdio>int z[10001],a,b,c,k=0;char h[6][11]={"FILL(1)","FILL(2)","DROP(1)","DROP(2)","POUR(1,2)","POUR(2,1)"};struct node{ int x,y,dis,z,pre;}q[50000];int vis[101][101];int bfs(){ int in=0,out=0,i; q[in].pre=-1; q[in].z=0; q[in].dis=0; q[in].x=0; q[in++].y=0; vis[0][0]=1; while(in>out) { int j=out; int x=q[out].x; int y=q[out].y; int di=q[out++].dis; if(x==c||y==c) { while(q[j].pre!=-1) { z[k++]=q[j].z; j=q[j].pre; } return di; } for(i=0;i<6;i++) { int sx=x,sy=y; switch(i) { case 0:sx=a;break; case 1:sy=b;break; case 2:sx=0;break; case 3:sy=0;break; case 4:sx=x+y-b>=0?x+y-b:0; sy=y+x>=b?b:y+x;break; case 5:sy=x+y-a>=0?x+y-a:0; sx=x+y>=a?a:x+y;break; } if(!vis[sx][sy]) { q[in].pre=out-1; q[in].z=i; vis[sx][sy]=1; q[in].dis=di+1; q[in].x=sx; q[in++].y=sy; } } } return 0;}int main(){ scanf("%d%d%d",&a,&b,&c); int di=bfs(); if(di) { printf("%d\n",di); for(int i=k-1;i>=0;i--) puts(h[z[i]]); } else printf("impossible\n");}
0 0
- POJ3414 Pots
- poj3414 Pots
- poj3414 Pots
- poj3414 - Pots
- POJ3414--Pots
- POJ3414 Pots
- poj3414 Pots
- poj3414 Pots
- POj3414 Pots
- poj3414 Pots
- POJ3414---Pots
- POJ3414--- Pots
- POJ3414 Pots
- POJ3414 Pots
- POJ3414-Pots
- POJ3414-Pots
- POJ3414 Pots
- POJ3414-Pots
- ArrayList,LinkedList,equals,hashcode,String的介绍
- 探析求树中两个节点p和q的最低公共祖先
- RTL8723BU移植
- 初学C语言:复制字符串中的元音字母
- CAS 引起的乱码问题解决
- POJ3414-Pots
- 【JZOJ 4678】钱仓
- [Java]Collection总结
- 基于Jmeter和Jenkins搭建性能测试框架
- 最小编辑代价
- poj 3009 Curling 2.0
- 数据结构实验之二叉树二:遍历二叉树
- hdu 5826 physics
- react native fect network request failed