其他分享
首页 > 其他分享> > 2019 GDUT Rating Contest I : Problem G. Back and Forth

2019 GDUT Rating Contest I : Problem G. Back and Forth

作者:互联网

题面:

G. Back and Forth

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 256 megabytes   Farmer John has two milking barns, each of which has a large milk tank as well as a storage closet containing 10 buckets of various sizes. He likes to carry milk back and forth between the two barns as a means of exercise. On Monday, Farmer John measures exactly 1000 gallons of milk in the tank of the first barn, and exactly 1000 gallons of milk in the tank of the second barn.

On Tuesday, he takes a bucket from the first barn, fills it, and carries the milk to the second barn, where he pours it into the storage tank. He leaves the bucket at the second barn.

On Wednesday, he takes a bucket from the second barn (possibly the one he left on Tuesday), fills it, and carries the milk to the first barn, where he pours it into the storage tank. He leaves the bucket at the first barn.

On Thursday, he takes a bucket from the first barn (possibly the one he left on Wednesday), fills it, and carries the milk to the second barn, where he pours it into the tank. He leaves the bucket at the second barn.

On Friday, he takes a bucket from the second barn (possibly the one he left on Tuesday or Thursday), fills it, and carries the milk to the first barn, where he pours it into the tank. He leaves the bucket at the first barn.

Farmer John then measures the milk in the tank of the first barn. How many possible different readings could he see?   Input The first line of input contains 10 integers, giving the sizes of the buckets initially at the first barn. The second line of input contains 10 more integers, giving the sizes of the buckets initially at the second barn. All bucket sizes are in the range 1...100.   Output Please print the number of possible readings Farmer John could get from measuring the milk in the tank of the first barn after Friday.   Example Input 1 1 1 1 1 1 1 1 1 2 5 5 5 5 5 5 5 5 5 5 Output 5   Note In this example, there are 5 possible results for the final amount of milk in the first barn’s tank:

题目描述:

农夫有两个奶牛棚,两个奶牛棚分别有一个牛奶缸和十个桶。两个牛奶缸刚开始都有1000加仑的牛奶。每过一天,农夫就会带一个桶从牛奶缸装满牛奶,走到另一个奶牛棚,然后把牛奶倒进这个牛奶棚牛奶缸。问过了这几天后,第一个牛奶缸可能有多少牛奶的情况的总数。  

题目分析:

这道题我们直接模拟就可以了,题目数据不大。但是为了更好的简洁代码,我们还是分析一下题目有什么性质: 题目会有三种情况: 1.没有改变: 2.四天只有其中两天“交换”了桶: 3.四天中都“交换”了桶: 从上面我们可以看到,牛奶缸的变化量取决于“交换”的桶的差值。所以,我们在模拟的过程中记录桶的差值就可以得出有多少种情况,能达到某种情况就记录下来。 我们可以用c++ stl set来记录我们获得的情况(不知道为什么用数组记录不行

标签:Rating,GDUT,tank,Contest,second,rst,he,milk,barn
来源: https://www.cnblogs.com/happy-MEdge/p/10517186.html