11877 The Coco-Cola Store
题目: 11877 The Coco-Cola Store
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 many
full 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). The
input 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.
Spoiler
Let me tell you how to drink 5 full bottles with 10 empty bottles: get 3 full bottles with 9 empty
bottles, drink them to get 3 empty bottles, and again get a full bottle from them. Now you have 2
empty bottles. Borrow another empty bottle from the shop, then get another full bottle. Drink it, and
finally return this empty bottle to the shop!
Sample Input
3
10
81
0
Sample Output
1
5
40
思路:
每次用现有的空瓶n除以3,商就是新的兑换数,余数加上商就是新的的空瓶数,如此循环到新的空瓶子数小于3时跳出循环。
如果剩下两个空瓶,可以先借一瓶,再还空瓶。
#include <iostream>
using namespace std;
int main()
{
int n,i,j,x,y,sum;
cin>>n;
while(n!=0)
{
sum=0;
while(n>=3)
{
x=n%3;
y=n/3;
sum=sum+y;
n=y+x;
}
if(n==2)
sum++;
cout<<sum<<endl;
cin>>n;
}
return 0;
}
11877 The Coco-Cola Store的更多相关文章
- Home · chineking/cola Wiki
Home · chineking/cola Wiki Home Cola Cola是一个分布式的爬虫框架,用户只需编写几个特定的函数,而无需关注分布式运行的细节.任务会自动分配到多台机器上,整个过程对 ...
- iOS之App Store上架被拒Legal - 5.1.5问题
今天在看到App Store 上架过程中,苹果公司反馈的拒绝原因发现了这么一个问题: Legal - 5.1.5 Your app uses background location services ...
- 发布APP到app store
好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...
- External Configuration Store Pattern 外部配置存储模式
Move configuration information out of the application deployment package to a centralized location. ...
- redux-devtools 浏览器修改Store值
1. npm install --save-dev redux-devtools 2. npm instal. --redux-devtools-dock-monitor 3. 创建DevTools ...
- NopCommerce 在Category 显示 Store List列表
实现效果如下: 1.在前台Web的Category Menu显示 Store; 2.点击 Store 显示 Store List列表: 3.点击 列表Store 的 Company Name 进入该S ...
- Redux原理(一):Store实现分析
写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何管理stat ...
- 这两天遇到iphone使用app store下载免费软件,必须验证付款信息才能购物是怎么回事???
答案: 在你这台设备上再设置一下,具体方法是:1.点设置进入2.点iTunes Store 和App Store 3.点 Apple ID ,如果没设置,设置一下,如果有的,再点击 4.出现一上选择的 ...
- 本地数据Store。Cookie,Session,Cache的理解。Timer类主要用于定时性、周期性任务 的触发。刷新Store,Panel
本地数据Store var monthStore = Ext.create('Ext.data.Store', { storeId : 'monthStore', autoLoad : false, ...
随机推荐
- C++ 简单的学生信息管理系统
// // main.cpp // 2013-7-17作业1 // // Created by 丁小未 on 13-7-17. // Copyright (c) 2013年 dingxiaowei. ...
- VPS -Digital Ocean -初试以及VPN的搭建
首先恭喜你找到这篇博客,它会带你走出困境. 题外话(请忽略):一直以来想搞一个VPS,终于在自己的刺激下试了一下Digital Ocean,还没有使用很长时间不做太多评论,唯一给我的感觉是各种操作还算 ...
- Android自动化压力测试之Monkey Test 异常解读(五)
monkey结果分类 monkey结果详细解读 monkey运行log输出后,得读懂日志内容,定位错误 lgo日志顺序输出分别为 测试命令信息.随机事件流(11种事件).异常信息(anr.crash ...
- loadrunner通过C语言实现字符的替换(只能替换单个字符,慎用)
如果按照普通的定义字符串就会出现以下错误: 解决方法如下: 将双引号改成单引号: lr_searchReplace(abc,"test",' ','+'); Action也可以这些 ...
- SpringJMS解析2-JmsTemplate
尽管消息接收可以使用消息监听器的方式替代模版方法,但是在发送的时候是无法替代的,在Spring中必须要使用JmsTemplate提供的方法来进行发送操作,可见JmsTemplate类的重要性,那么我们 ...
- Spring事务解析4-切面织入
BeanFactoryTransactionAttributeSourceAdvisor作为Advisor的实现类,自然要遵从Advisor的处理方式,当代理被调用时会调用这个类的增强方法,也就是此b ...
- Swift3.0语言教程使用Unicode范式标准化获取字符串
Swift3.0语言教程使用Unicode范式标准化获取字符串 Swift3.0语言教程使用Unicode范式标准化获取字符串,在NSString中可以使用4个属性去使用Unicode范式标准化获取字 ...
- 移动网页 -- CSS布局
1.多栏结构 column-count column-width column:120px 3: column-gap:2em: column-rule:2px dotted gray: 跨越以及打断 ...
- js三级省市区选择
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Linux 命令集合
1.find /etc -name "*" | xargs grep "hello abcserver" 按照内容过滤2.grep -v "^#&qu ...