| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1511 人关注过本帖, 1 人收藏
标题:jugs,谁来和我一起做,有点难!
取消只看楼主 加入收藏
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏(1)
 问题点数:0 回复次数:6 
jugs,谁来和我一起做,有点难!
Problem Description
In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle.

You have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use: (1) you can fill a jug, (2) you can empty a jug, and (3) you can pour from one jug to the other. Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A.

A problem is given by a triple (Ca,Cb,N), where Ca and Cb are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in jug B. The possible steps are

fill A
fill B
empty A
empty B
pour A B
pour B A
success

where "pour A B" means "pour the contents of jug A into jug B", and "success" means that the goal has been accomplished.

You may assume that the input you are given does have a solution.


 

Input
Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: Ca, Cb, and N. Ca and Cb are the capacities of jugs A and B, and N is the goal. You can assume 0 < Ca <= Cb and N <= Cb <=1000 and that A and B are relatively prime to one another.


 

Output
Output from your program will consist of a series of instructions from the list of the potential output lines which will result in either of the jugs containing exactly N gallons of water. The last line of output for each puzzle should be the line "success". Output lines start in column 1 and there should be no empty lines nor any trailing spaces.


 

Sample Input
3 5 4
5 7 3
 

Sample Output
fill B
pour B A
empty A
pour B A
fill B
pour B A
success
fill A
pour A B
fill A
pour A B
empty B
pour A B
success
搜索更多相关主题的帖子: jugs 
2008-07-24 20:59
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
回复 2# coming 的帖子
题目的准确意思我也不太明白,有谁能解释一下的?
2008-07-24 21:37
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
回复 4# 病书生 的帖子
知道了,太感谢了,看来接下来就是算法问题了。
2008-07-25 07:42
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
谁有什么好的解决方案?思路?先谢谢了。
2008-07-25 09:09
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
回复 7# carmen0531 的帖子
恩,我会试试的。关于树的应用,因为还没学数据结构,我得先去看书了。谢谢指点,有问题的话能直接问你吗?
2008-07-25 12:29
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
回复 9# carmen0531 的帖子
没事,实在写不出来就先放着,学的多了以后这些题就会做了。以后还有题目希望也可以和你讨论。
2008-07-26 18:02
xujie3
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:51
专家分:0
注 册:2008-7-22
收藏
得分:0 
回复 10# unicafree 的帖子
呵呵。。。很感谢来帮我。
2008-07-26 18:03
快速回复:jugs,谁来和我一起做,有点难!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016423 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved