The Coco-Cola Store
UVA11877
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
题意:
3个空瓶子可以换1瓶可乐,输入告诉你会有多少空瓶子,输出回答可以换到多少可乐
方法一:
使用模拟的方法做:
代码:
#include"iostream"
using namespace std;
const int maxn=110;
int main()
{
int ca,n;
while(cin>>n&&n)
{
ca=0;
while(n>2)
{
n-=3;
ca++;
n+=1;
}
if(n==2)
{
ca++;
}
cout<<ca<<endl;
} return 0; } 方法二:
其实只要输出每次的n/2就可以了 代码
#include"iostream"
using namespace std;
int main()
{
int n;
while(cin>>n&&n)
{
if(n!=2)
cout<<n/2<<endl;
else
cout<<1<<endl;
}
return 0;
}
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, ...
- 点击页面判断是否安装app并打开,否则跳转app store的方法
常常有这样的场景,咱们开发出来的APP需要进行推广,比如在页面顶部来一张大Banner图片,亦或一张二维码.但往往我们都是直接给推广图片加了一个下载链接(App Store中的).所以咱们来模拟一下用 ...
随机推荐
- Nginx系列篇四:Nginx+keepalived搭建一个高可用的双机双主热备
建议:先阅读Nginx+keepalived主从配置,因为此篇是接着上篇开始的 上一篇我们简单的介绍了主从配置及其缺点,我们看一下双主热备配置: 2台Nginx+keepalived互为主备,各自绑定 ...
- CSS3鼠标放上去旋转代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Jmeter之聚合报告
1.添加线程组,添加请求接口 2.设置线程组 3.线程组右击添加—>监听器—>聚合报告
- Iahub and Xors Codeforces - 341D
二维线段树被卡M+T...于是去学二维树状数组区间更新区间查询 树状数组维护数列区间xor的修改.删除(就是把原问题改成一维): 以下p*i实际都指i个p相xor,即(i&1)*pa表示原数列 ...
- 18.3.1获得Class对象
package d18_3_1; /** * Java中的java.lang.Class,简单理解就是为每个java对象的类型标识的类, * 虚拟机使用运行时类型信息选择正确的执行方法,用来保存这些运 ...
- 进度条--ProgressBar和BackgroundWorker
1) 需求:就餐打卡数据处理后,插入数据库中,用进度条显示过程 2) 思路:总进度为txt文本文件的行数(数据都是按照行写入),文本文件的大小 //BackgroundWorker对象有三个主要的事件 ...
- Asp.net 字符(一)
1.字母大小写处理 private string GetChangedStr(string oldStr, strType type) { string newStr = ""; ...
- react ant design路由配置
最初的时候,只使用了antd中的menu,header和footer都是自己写的组件,在写路由时,总是报如下错误: 相关的路由配置如下: 在网上查的说是组件未暴露出去或者是return 这一行必须有个 ...
- 后TOS时代的码头数字化生产力
之前看过一篇文章是,是INFORM的副总裁写的关于以TOS外挂模式提升码头生产效能的文章.文章对外挂模式的总结挺好的,我最近也一直从事这块的工作,以此文梳理一下前面的经验,记录一下自己的感想. TOS ...
- Knockout-了解Observable与computed
KO是什么? KO不是万能的,它的出现主要是为了方便的解决下面的问题: UI元素较多,用户交互比较频繁,需要编写大量的手工代码维护UI元素的状态.样式等属性? UI元素之间关系比较紧密,比如操作一个元 ...