UVa 11150 Cola (water ver.)

11150 - Cola

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2091

You see the following special offer by the convenience store:

" A bottle of Choco Cola for every 3 empty bottles returned "

Now you decide to buy some (say N) bottles of cola from the store. You would like to know how you can get the most cola from them.

The figure below shows the case where N = 8.Method 1 is the standard way: after finishing your 8 bottles of cola, you have 8 empty bottles. Take 6 of them and you get 2 new bottles of cola. Now after drinking them you have 4 empty bottles, so you take 3 of them to get yet another new cola. Finally, you have only 2 bottles in hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2 + 1 = 11 bottles of cola.

You can actually do better! In Method 2, you first borrow an empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you will have to return your remaining empty bottle back to your friend.

Input

Input consists of several lines, each containing an integer N (1 ≤N ≤ 200).  

Output

For each case, your program should output the maximum number of bottles of cola you can enjoy. You may borrow empty bottles from others, but if you do that, make sure that you have enough bottles afterwards to return to them.

Sample Input

8

Sample Output

12

Note: Drinking too much cola is bad for your health, so... don't try this at home!! :-)

完整代码:

/*0.012s*/

#include<cstdio>  

int main()
{
    int n, sum;
    while (~scanf("%d", &n))
    {
        sum = n;
        while (n > 2)
        {
            sum += n / 3;
            n -= n / 3 * 2;
        }
        if (n == 2) ++sum;
        printf("%d\n", sum);
    }
    return 0;
}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索from
, of
, Empty
, The
, You
have
water vs cola、11150、代码11150、本铺中村屋 11150、zetacola,以便于您获取更多的相关知识。

时间: 2024-08-03 10:34:37

UVa 11150 Cola (water ver.)的相关文章

UVa 12289 One-Two-Three (water ver.)

12289 - One-Two-Three Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_problem&problem=3710 Your little brother has just learnt to write one, two and three, in English

UVa 514 Rails (water ver.)

514 - Rails Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=455 There is a famous railway station in PopPush City. Country there is incredibly hilly. The

UVa 11340 Newspaper (water ver.)

11340 - Newspaper Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2315 News agency pays money for articles according to some rules. Each character has its

UVa 10082 WERTYU (water ver.)

10082 - WERTYU Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1023 A common typing error is to place the hands on the keyboard one row to the right of th

UVa 10696 f91 (water ver.)

10696 - f91 Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1637 Background McCarthy is a famous theorician of computer science. In his work, he defined a

UVa 79 ClockHands (water ver.)

579 - ClockHands Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=520 The medieval interest in mechanical contrivances is well illustrated by the developme

UVa 10656 Maximum Sum (II) (water ver.)

10656 - Maximum Sum (II) Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1597 In a given a sequence of non-negative integers you will have to find such a

UVa 11727 Cost Cutting (water ver.)

11727 - Cost Cutting Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2827 Company XYZ have been badly hit by recession and is taking a lot of cost cutting

UVa 10300 Ecological Premium (water ver.)

10300 - Ecological PremiumTime limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=1241 German farmers are given a premium depending on the conditions at their far