POJ3414---Pots
来源:互联网 发布:关于网络交易的法律 编辑:程序博客网 时间:2024/06/01 08:04
#include<iostream>#include<stdio.h>#include<string>#include<algorithm>#include<string.h>#include<queue>using namespace std;#define MAXN 110char str[6][10]={"FILL(1)", "FILL(2)", "DROP(1)", "DROP(2)", "POUR(1,2)", "POUR(2,1)"};int a,b,c;int vis[MAXN][MAXN];pair<int,int>pre[MAXN][MAXN];struct node{int a,b,t;};void print(int dx,int dy){ if(dx!=0||dy!=0){ int x=pre[dx][dy].first; int y=pre[dx][dy].second; print(x,y); printf("%s\n",str[vis[dx][dy]]);//输出 }}void bfs(int a,int b,int c){ queue<node>q; node ft,tp; ft.a=0,ft.b=0,ft.t=0; q.push(ft); while(!q.empty()){ tp=q.front(); q.pop(); if(tp.a==c||tp.b==c){ printf("%d\n",tp.t); print(tp.a,tp.b); return ; } for(int i=0;i<6;i++){ node next=tp; if(i==0) next.a=a; else if(i==1) next.b=b; else if(i==2) next.a=0; else if(i==3) next.b=0; else if(i==4) {//a给b倒水,要判断能不能倒满 int t=min(next.a,b-next.b); next.a-=t;next.b+=t; } else if(i==5){ int t = min(a-next.a,next.b); next.b-=t; next.a+=t; } next.t++; if(vis[next.a][next.b]==-1){ pre[next.a][next.b]=make_pair(tp.a,tp.b);//记录路径 vis[next.a][next.b]=i; q.push(next); } } } printf("impossible\n");}int main(){ while(scanf("%d%d%d",&a,&b,&c)!=EOF){ memset(vis,-1,sizeof vis); vis[0][0]=0; bfs(a,b,c); } 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
- sed命令
- Cocoapods的安装和常见问题解决
- 数据库SQLite
- CentOS6.4 NFS配置
- 在CentOS 7中安装与配置Tomcat-8方法
- POJ3414---Pots
- 修复了WebCalendar.js日期控件在firefox下星期显示错误问题
- java ___ HashCode 和 equals ()
- 内核中的current宏
- 初学MFC——如何弹出你做的对话框
- 2015-6-13
- Ogre的SceneManager分析
- .NET学习目录
- 绘图参数设置函数par()详解