博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3414 Pots (BFS)
阅读量:6849 次
发布时间:2019-06-26

本文共 2246 字,大约阅读时间需要 7 分钟。

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

Description

You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:

  1. FILL(i)        fill the pot i (1 ≤ ≤ 2) from the tap;
  2. DROP(i)      empty the pot i to the drain;
  3. POUR(i,j)    pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j).

Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots.

Input

On the first and only line are the numbers AB, and C. These are all integers in the range from 1 to 100 and C≤max(A,B).

Output

The first line of the output must contain the length of the sequence of operations K. The following K lines must each describe one operation. If there are several sequences of minimal length, output any one of them. If the desired result can’t be achieved, the first and only line of the file must contain the word ‘impossible’.

Sample Input

3 5 4

Sample Output

6FILL(2)POUR(2,1)DROP(1)POUR(2,1)FILL(2)POUR(2,1)

Source

, Western Subregion
 
 
1 #include
2 #include
3 #include
4 #include
5 6 using namespace std; 7 8 const int maxn=110; 9 10 string op[7]={
"","FILL(1)","FILL(2)","DROP(1)","DROP(2)","POUR(2,1)","POUR(1,2)"};11 12 int l,r;13 int a,b,c;14 int vis[maxn][maxn],step[maxn*maxn];15 16 struct node{17 int x,y;18 int opr;19 int pre;20 }info[maxn*maxn];21 22 void Solve(int x,int y,int opr){23 if(vis[x][y])24 return ;25 vis[x][y]=1;26 info[r].x=x;27 info[r].y=y;28 info[r].opr=opr;29 info[r].pre=l;30 r++;31 }32 33 void Print(){34 int ans=0;35 while(l!=0){36 step[ans++]=info[l].opr;37 l=info[l].pre;38 }39 printf("%d\n",ans);40 for(int i=ans-1;i>=0;i--)41 cout<
<
=r)84 printf("impossible\n");85 }86 87 int main(){88 89 //freopen("input.txt","r",stdin);90 91 while(~scanf("%d%d%d",&a,&b,&c)){92 memset(vis,0,sizeof(vis));93 BFS();94 }95 return 0;96 }

 

转载地址:http://dvrul.baihongyu.com/

你可能感兴趣的文章
mysql—Access denied for user 'root'@'localhost' (using password:NO)
查看>>
hibernate 懒加载异常
查看>>
python3的zip函数
查看>>
《Git权威指南》读书笔记 第四章 git初始化
查看>>
《Head first HTML与CSS 第二版》读书笔记 第九章 盒模型
查看>>
《Python面向对象……》之目录
查看>>
集群入门简析及LB下LVS详解
查看>>
Linux与GPT
查看>>
管理或技术
查看>>
分配到弱属性;对象将在赋值之后释放
查看>>
java作用域public ,private ,protected 及不写时的区别
查看>>
until循环语句
查看>>
Android桌面悬浮窗进阶,QQ手机管家小火箭效果实现
查看>>
提高用户体验方式:饥饿营销
查看>>
Java8中的LocalDateTime工具类
查看>>
Exchange 2013 PowerShell创建自定义对象
查看>>
RAID-10 阵列的创建(软)
查看>>
javaScript的调试(四)
查看>>
nginx不使用正则表达式匹配
查看>>
利用putty进行vnc + ssh tunneling登录
查看>>