汽水兑换

题目描述 Description

为了回收玻璃汽水瓶,汽水公司做出如下推广活动,两个空瓶即可免费兑换一瓶新的汽水。现在小明家攒了n个空瓶子,问小明一共可以兑换多少瓶汽水?

输入描述 Input Description

小明现在有的空瓶子数n,(10<=n<=100)

输出描述 Output Description

能免费兑换的最多汽水数量。

样例输入 Sample Input

10

样例输出 Sample Output

9

 

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int num=0;
 6 void f(int x)
 7 {
 8     if(x<2)
 9         return;
10     num+=x/2;
11     f(x/2+x%2);
12 }
13 
14 int main()
15 {
16     int n;
17     cin>>n;
18     f(n);
19     cout<<num;
20     return 0;
21 }

 

posted @ 2019-02-21 14:08  zhangjs73  阅读(389)  评论(0)    收藏  举报