USACO 1.4 Mother's Milk
2015-09-10 01:03
387 查看
Mother's Milk
Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty while bucket C is full of milk. Sometimes, FJ pours milk from one bucket to
another until the second bucket is filled or the first bucket is empty. Once begun, a pour must be completed, of course. Being thrifty, no milk may be tossed out.
Write a program to help FJ determine what amounts of milk he can leave in bucket C when he begins with three buckets as above, pours milk among the buckets for a while, and then notes that bucket A is empty.
A single line with the three integers A, B, and C.
A single line with a sorted list of all the possible amounts of milk that can be in bucket C when bucket A is empty.
Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty while bucket C is full of milk. Sometimes, FJ pours milk from one bucket to
another until the second bucket is filled or the first bucket is empty. Once begun, a pour must be completed, of course. Being thrifty, no milk may be tossed out.
Write a program to help FJ determine what amounts of milk he can leave in bucket C when he begins with three buckets as above, pours milk among the buckets for a while, and then notes that bucket A is empty.
PROGRAM NAME: milk3
INPUT FORMAT
A single line with the three integers A, B, and C.
SAMPLE INPUT (file milk3.in)
8 9 10
OUTPUT FORMAT
A single line with a sorted list of all the possible amounts of milk that can be in bucket C when bucket A is empty.
SAMPLE OUTPUT (file milk3.out)
1 2 8 9 10
SAMPLE INPUT (file milk3.in)
2 5 10
SAMPLE OUTPUT (file milk3.out)
5 6 7 8 9 10
题意: Farmer John有三个桶A,B,C,输入三个桶的容积;开始时桶A和第桶B为空,桶C为满。
Farmer John要做pours milk操作,把桶x的牛奶导入桶y中,除非桶y被倒满或桶x已倒空,一次操作算作结束。
进行n次倒牛奶操作改变C桶中牛奶的余量,但要求终止时A桶要为空。
问:C桶中牛奶的余量一共有多少种情况。
题解: 一共有6种操作 A->B;A->C; B->A;B->C; C->A;C->B;
用宽搜就可以了做出来,但感觉这次我写的代码好丑,过于冗余。
ps:本人大三狗一枚,正在持续更新博客,文章里有任何问题,希望各位网友可以指出。若有疑问也可在评论区留言,我会尽快回复。希望能与各位网友互相学习,谢谢
相关文章推荐
- USACO 3.2.2:Stringsobits
- USACO 3.1 Shaping Regions
- 【解题报告】【USACO】酸奶工厂
- usaco-Calf Flac
- usaco/1.1 Your Ride Is Here
- usaco/1.1 Greedy Gift Givers
- usaco/1.1 Friday the Thirteenth
- usaco/ 1.1 Broken Necklace
- USACO/fact4 3.2.1
- USACO/spin 3.2.3
- USACO/rockers 3.4.4 动态规划
- USACO 2.2 Party Lamps
- USACO 2.2 Runaround Numbers
- USACO 2.2 Subset Numbers
- USACO 2.2 Preface Numbering
- USACO 2.1 Ordered Fractions
- USACO 2.1 Hamming Codes
- USACO 2.1 Healthy Holsteins
- USACO 2.1 Sorting A Three-Valued Sequence
- USACO 2.1 The Castle