POJ3414 Pots
来源:互联网 发布:北京赛车pk10辅助软件 编辑:程序博客网 时间:2024/05/16 12:52
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <queue>using namespace std;struct node{ int a,b,t; bool operator < (const node &tmp)const{ return t > tmp.t; }};struct path{ int x,y;}pa[105][105];int a,b,c;int vis[105][105];priority_queue<node> q;void solve(int a,int b,node cur,int mode){ if(!vis[a][b]){ vis[a][b] = mode; pa[a][b].x = cur.a; pa[a][b].y = cur.b; q.push(node{a,b,cur.t+1}); }}node bfs(){ node cur; while(!q.empty()) q.pop(); memset(vis,0,sizeof(vis)); vis[0][0] = -1; pa[0][0].x = -1; pa[0][0].y = -1; q.push(node{0,0,0}); while(!q.empty()){ cur = q.top(); q.pop(); if(cur.a == c || cur.b == c){ return cur; } //一共6种状态 //1.fill:a solve(a,cur.b,cur,1); //2.fill:b solve(cur.a,b,cur,2); //3.drop:a solve(0,cur.b,cur,3); //4.drop:b solve(cur.a,0,cur,4); //5.pour:a->b if(cur.a >= b-cur.b){ solve(cur.a-(b-cur.b),b,cur,5); } else{ solve(0,cur.a+cur.b,cur,5); } //6.pour:b->a if(cur.b >= a-cur.a){ solve(a,cur.b-(a-cur.a),cur,6); } else{ solve(cur.a+cur.b,0,cur,6); } } return node{-1,-1,-1};}void printpath(int x,int y,int t){ if(!t) return ; printpath(pa[x][y].x,pa[x][y].y,t-1); switch(vis[x][y]){ case 1: printf("FILL(1)\n");break;case 2:printf("FILL(2)\n");break;case 3:printf("DROP(1)\n");break;case 4:printf("DROP(2)\n");break;case 5:printf("POUR(1,2)\n");break;case 6:printf("POUR(2,1)\n");break; }}int main(){ while(~scanf("%d%d%d",&a,&b,&c)){ node ans = bfs(); if(ans.t < 0) printf("impossible\n"); else{ printf("%d\n",ans.t); printpath(ans.a,ans.b,ans.t); } } return 0;}
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
- Android进阶——git上传代码到coding.net
- 拓胜培训Java,每天的点点滴滴
- H5页面设计
- Applied Natural Language Processing —— 读书笔记 第二章
- 进度条
- POJ3414 Pots
- HDU5595(水题+数学)
- 8位bmp图片格式详细说明文档
- 5.Which SQL statements would display the value 1890.55 as $1,890.55? (Choose three .)
- FZU2150 Fire Game
- 堡垒机 | 跳板机 | 中控机
- java面向对象及其特性初探
- [Python标准库]random——伪随机数生成器
- 网络工具类代码---单例(上传文件等等,发送网络请求)