您的位置:首页 > 其它

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.


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