Mixing Milk [洛谷] (模拟) /*rank*/

原题传送门


题面:

Mixing Milk

                           time limit per test : 1 second
                       memory limit per test : 256 megabytes
                                input : standard input
                               output : standard output

Problem Description

Farming is competitive business – particularly milk production. Farmer John figures that if he doesn’t innovate in his milk production methods, his dairy business could get creamed! Fortunately, Farmer John has a good idea. His three prize dairy cows Bessie, Elsie, and Mildred each produce milk with a slightly different taste, and he plans to mix these together to get the perfect blend of flavors.

To mix the three different milks, he takes three buckets containing milk from the three cows. The buckets may have different sizes, and may not be completely full. He then pours bucket 1 into bucket 2, then bucket 2 into bucket 3, then bucket 3 into bucket 1, then bucket 1 into bucket 2, and so on in a cyclic fashion, for a total of 100 pour operations (so the 100th pour would be from bucket 1 into bucket 2). When Farmer John pours from bucket a into bucket b, he pours as much milk as possible until either bucket a becomes empty or bucket b becomes full.

Please tell Farmer John how much milk will be in each bucket after he finishes all 100
pours.

Input

The first line of the input file contains two space-separated integers: the capacity c1 of the first bucket, and the amount of milk m1 in the first bucket. Both c1 and m1 are positive and at most 1 billion, with c1≤m1. The second and third lines are similar, containing capacities and milk amounts for the second and third buckets.

Output

Please print three lines of output, giving the final amount of milk in each bucket, after 100 pour operations.

Sample Input

10 3
11 4
12 5

Sample Output

0
10
2

题意描述

这个农夫很无聊的把牛奶从桶1倒到桶2,又从桶2倒到桶3,再从桶3倒到桶1.如此循环,直到他倒牛奶的次数到达100.求出如此操作后三个桶内的牛奶多少.

题目分析

反正只倒100次而已,直接模拟就可以了,倒牛奶必定是上一个桶为空或者是下一个桶满了为止.(这题告诉我要勇于开题,说不定就开出水题了 )

具体代码

#include 
#include 
using namespace std;
int T[4], I[4];
int main()
{
    for(int i = 1; i <= 3; i++)
    {
        scanf("%d%d", &T[i], &I[i]);
    }
    for(int i = 1; i <= 100; i++)
    {
        if(i%3 == 1)
        {
            if(I[1]+I[2] >= T[2])
            {
                I[1] -= T[2]-I[2];
                I[2] = T[2];
            }
            else
            {
                I[2] += I[1];
                I[1] = 0;
            }
        }
        else if(i%3 == 2)
        {
            if(I[2]+I[3] >= T[3])
            {
                I[2] -= T[3]-I[3];
                I[3] = T[3];
            }
            else
            {
                I[3] += I[2];
                I[2] = 0;
            }
        }
        else
        {
            if(I[3]+I[1] >= T[1])
            {
                I[3] -= T[1]-I[1];
                I[1] = T[1];
            }
            else
            {
                I[1] += I[3];
                I[3] = 0;
            }
        }
    }
    for(int i = 1; i <= 3; i++)
    {
        printf("%d\n", I[i]);
    }
    return 0;
}

你可能感兴趣的:(模拟)