Classic
Clean & simple
Crystal
Glassmorphism + Neon
Cyberpunk
Neon glitch art
🚫
违规Action检测
禁止Use右键菜单
⚠️ 此Action已被系统记录
1

Jugs

📝 Solutions 🔵 仅限 C++
Problems Description
<p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> 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. </p> <p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> &nbsp;&nbsp;&nbsp; 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. </p> <p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> &nbsp;&nbsp;&nbsp; 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 </p> <p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> &nbsp;&nbsp;&nbsp; fill A&nbsp;<br /> &nbsp;&nbsp;&nbsp; fill B&nbsp;<br /> &nbsp;&nbsp;&nbsp; empty A&nbsp;<br /> &nbsp;&nbsp;&nbsp; empty B&nbsp;<br /> &nbsp;&nbsp;&nbsp; pour A B&nbsp;<br /> &nbsp;&nbsp;&nbsp; pour B A&nbsp;<br /> &nbsp;&nbsp;&nbsp; success </p> <p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> &nbsp;&nbsp;&nbsp; where "pour A B" means "pour the contents of jug A into jug B", and "success" means that the goal has been accomplished. </p> <p style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;"> &nbsp;&nbsp;&nbsp; You may assume that the input you are given does have a solution. </p> <p> <span id="1360921774759S">&nbsp;</span> </p>
Input格式
<p> <span style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;line-height:25px;">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 &lt; Ca &lt;= Cb and N &lt;= Cb &lt;=1000 and that A and B are relatively prime to one another.&nbsp;</span> </p>
Output格式
<p> <span style="color:#333333;font-family:'MicroSoft Yahei', Helvetica, Arial, Georgia, Simsun;font-size:14px;line-height:25px;">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.</span> </p>
Sample
Sample Input 1
3 7 1 9 32 6
Sample Output 1
fill B pour B A empty A pour B A success fill B pour B A empty A pour B A empty A pour B A empty A pour B A fill B pour B A empty A pour B A empty A pour B A empty A pour B A empty A pour B A fill B pour B A empty A pour B A empty A pour B A success
Submit Code
请先Login后Submit

🤖 AI 解题助手

OpenRouter
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这problems题,可以帮你points析思路、提供Code示例。
🔓 完全Free · 无需消耗 Token