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.

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

Sample Input

8

Sample Output

12

问题链接:UVA11150 Cola

问题简述:(略)

问题分析

喝可乐,每3个空瓶可以换一瓶可乐,迭代计算问题。

如果最后剩下2瓶则可以换一瓶。喝掉这2瓶再从朋友那里借一个空瓶,3个空瓶换一瓶,喝了之后,将空瓶还给朋友。

既然2瓶可以喝3瓶,那直接用数学公式算就可以了,时间复杂度为O(1)。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA11150 Cola */#include <bits/stdc++.h>using namespace std;int main()
{int n;while(~scanf("%d", &n))printf("%d\n", (n / 2 )* 3 + n % 2);return 0;
}

AC的C++语言程序(模拟法)如下:

/* UVA11150 Cola */#include <bits/stdc++.h>using namespace std;int main()
{int n, ans;while(~scanf("%d", &n)) {ans = n;while(n >= 3) {ans += n / 3;n = n / 3 + n % 3;}if(n == 2)ans++;printf("%d\n", ans);}return 0;
}

UVA11150 Cola【数学】相关推荐

  1. JSK-337 汽水瓶【数学+模拟】

    汽水瓶 有这样一道智力题:"某商店规定:三个空汽水瓶可以换一瓶汽水.小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?"答案是 5 瓶,方法如下:先用 9 个空瓶子换 3 瓶汽水, ...

  2. TYUT-A2专题题解

    TYUT-A2专题题解 循序渐进,基础练起. 01递推与组合 HDU1210 Eddy's 洗牌问题[递推函数+模拟] - 海岛Blog - CSDN博客 HDU2044 一只小蜜蜂...[递推] - ...

  3. TYUT-A专题题解(一)

    TYUT-A专题题解(一) 01A Ad Hoc UVA353 LA5247 Pesky Palindromes[回文] - 海岛Blog - CSDN博客 UVA947 Master Mind He ...

  4. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  5. Competitive Programming专题题解(1)

    Competitive Programming题解 AOAPC I: Beginning Algorithm Contests 题解 CP2-1.1.1 Easy(Ad Hoc Problems) P ...

  6. ACM程序设计基础题解

    ACM水题一 HDU1262 寻找素数对[素数] - 海岛Blog - CSDN博客 HDU4548 美素数[水题] - 海岛Blog - CSDN博客 HDU2503 a/b + c/d[水题] - ...

  7. ACM程序设计基础(2)题解

    ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...

  8. ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》

    第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...

  9. 群论中的拉格朗日定理(子群的阶必然能整除群阶---数学

    前言:仅个人小记.本文记录的证明逻辑上不具有流畅性,主要是在一开始不流畅,拉格朗日神乎其技地引入了一个等价关系,进而实现了整个定理的证明,目前我没能给出拉格朗日是如何想到引入该等价关系. 最后给出推论 ...

最新文章

  1. 批量生成销售订单、退货订单
  2. boost::intrusive::treap_algorithms用法的测试程序
  3. javaweb简要介绍,虚拟路径,虚拟主机
  4. Eclipse更改默认工作目录的方法
  5. java对象转json格式
  6. java mysql 分页计算公式_关于Java的分页算法,急!
  7. (转)uml 交互视图
  8. 什么情况下使用weak关键字,相比assign有什么不同
  9. 计算机网络的主要功能四种,计算机网络应用基础概述
  10. 视频伪原创消重 抖音视频md5修改在线
  11. 工作缺点和不足及措施_个人总结缺点和不足
  12. 传奇泡点地图制作脚本
  13. 将姓名转为拼音,首字母大写
  14. 淘宝关键词搜索采集商品价格销量接口分析商品价格走势(商品列表接口,商品销量接口,商品价格接口,分类ID采集精准商品数据接口)接口代码对接流程
  15. qt5把qt_zh_CN.qm加载了,但QTextEdit的右键菜单仍然是英文,而QLineEdit的倒是中文。怎样设置使得QTextEdit的右键菜单是中文
  16. tableau新新手指南(基础功能介绍)
  17. 【数据结构】 栈的知识点
  18. python找素数程序_求素数python
  19. 50 个杀手级人工智能项目
  20. sql-子查询当作字段返回提示至过多

热门文章

  1. ArcGIS Pro快速汉化方法
  2. 作为开发者不应该畏惧的8件事
  3. VC.dll相关及其C#交互
  4. 线程重命名java_线程重命名(Netty)和设计模式Decorator
  5. jfinal 一对一 实体类怎么写_新祥旭考研一对一:考前必知的四大答题技巧
  6. 计算机连接打印机用户数量修改,win7电脑中局域网限制每台打印机的使用成员数量的方法...
  7. python3 科学计算_python3 科学计算之pandas入门(一)
  8. tensorflow中协调器 tf.train.Coordinator 和入队线程启动器 tf.train.start_queue_runners
  9. 马士兵_JAVA自学之路(为那些目标模糊的码农们)
  10. 【解决】client does not support authentication