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/