UVA 11877 The Coco-Cola Store
来源:互联网 发布:小型公司网络搭建案例 编辑:程序博客网 时间:2024/05/17 23:39
Once upon a time, there is a special coco-cola store. If you return three empty bottles to the shop,
you’ll get a full bottle of coco-cola to drink. If you have n empty bottles right in your hand, how manyfull bottles of coco-cola can you drink?
Input
There will be at most 10 test cases, each containing a single line with an integer n (1 ≤ n ≤ 100). Theinput terminates with n = 0, which should not be processed.
Output
For each test case, print the number of full bottles of coco-cola that you can drink.
SpoilerLet me tell you how to drink 5 full bottles with 10 empty bottles: get 3 full bottles with 9 emptybottles, drink them to get 3 empty bottles, and again get a full bottle from them. Now you have 2empty bottles. Borrow another empty bottle from the shop, then get another full bottle.Drink it, andfinally return this empty bottle to the shop!
Sample Input
3
10
81
0
Sample Output
1
5
40
代码实现
#include<iostream>#include<cstdio>using namespace std;int main(){ int n; while(scanf("%d",&n)==1&&n) { if(n%2==0) printf("%d\n",n/2); if(n%2==1) printf("%d\n",(n-1)/2); } return 0;}
题解
列出n从 0到10的结果
1……0;
2……1
3……1
4……2
5……2
6……3
7……3
8……4
9……4
10……5
发现规律:
当n为奇数时
得到的可乐为(n-1)/2瓶
当n为偶数时
得到的可乐为 n/2 瓶
- UVa 11877 - The Coco-Cola Store
- UVA 11877 The Coco-Cola Store
- UVA 11877 The Coco-Cola Store(数学题)
- UVaOJ 11877 The Coco-Cola Store(简单数学题)
- toj 4065 The Coco-Cola Store
- The Coco-Cola Store(湖南省第六届ACM竞赛题)
- UVa 11150 - Cola
- UVa 11150 Cola
- UVa 11150 Cola (water ver.)
- uva 10726 - Coco Monkey(数论)
- The Compiler Generator Coco/R
- Cola
- Coco
- Coco
- (1.1.4)uva 11150 Cola(直叙式模拟)
- UVa 10726 - Coco Monkey (数学 + 模拟)
- The Xen Store
- 11150 - Cola
- php和js中数组中分别循环找出最大的数。
- HDU 1398 Square Coins
- 2014华为机试(一)
- android混淆打包配置(忽略第三方jar)
- 开启新的学习模式
- UVA 11877 The Coco-Cola Store
- 字符集和字符编码Q&A
- android 学习笔记之 post get 方式与 服务器JSON通信
- JDK1.7 file monitor --- watch service api
- java EE之jsp脚本和3个编译指令 复习
- The first day
- java TCP客户端 服务端 互访
- 开发基于 IBM Lotus Domino 的 Web 2.0 应用的最佳实践
- Android Studio使用Git@SC分享项目