UVa 11150 Cola (Water ver.)

Source: Internet
Author: User

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

The following special offer by the convenience store:

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

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

The figure below shows the case where N = 8.Method 1 are 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 your have 4 empty bottles, so you take the them 3 of yet to get another new cola. Finally, you have only 2 bottles into hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2 + 1 = one bottles of cola.

Can actually do better! In Method 2, you borrow a empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = bottles of cola! Course, you'll 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

Your program should output the maximum number of bottles to cola you can enjoy. You could borrow empty bottles from others, but if you did so, make sure this you have enough bottles-afterwards to return To them.

Sample Input

8

Sample Output

12

Note:drinking too much cola are bad for your health, so ... don ' t try this in home!! :-)

Complete code:

/*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;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.