题目:    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的更多相关文章

  1. Home · chineking/cola Wiki

    Home · chineking/cola Wiki Home Cola Cola是一个分布式的爬虫框架,用户只需编写几个特定的函数,而无需关注分布式运行的细节.任务会自动分配到多台机器上,整个过程对 ...

  2. iOS之App Store上架被拒Legal - 5.1.5问题

    今天在看到App Store 上架过程中,苹果公司反馈的拒绝原因发现了这么一个问题: Legal - 5.1.5 Your app uses background location services ...

  3. 发布APP到app store

    好久好久没写博客了,主要是 都在学习新东西,忙不赢啊. 近段时间在用AC平台学习开发移动APP, 今天开始发布应用. 在ac云控制台编译成ipa后,使用apple提供的Application Load ...

  4. External Configuration Store Pattern 外部配置存储模式

    Move configuration information out of the application deployment package to a centralized location. ...

  5. redux-devtools 浏览器修改Store值

    1. npm install --save-dev redux-devtools 2. npm instal. --redux-devtools-dock-monitor  3. 创建DevTools ...

  6. NopCommerce 在Category 显示 Store List列表

    实现效果如下: 1.在前台Web的Category Menu显示 Store; 2.点击 Store 显示 Store List列表: 3.点击 列表Store 的 Company Name 进入该S ...

  7. Redux原理(一):Store实现分析

    写在前面 写React也有段时间了,一直也是用Redux管理数据流,最近正好有时间分析下源码,一方面希望对Redux有一些理论上的认识:另一方面也学习下框架编程的思维方式. Redux如何管理stat ...

  8. 这两天遇到iphone使用app store下载免费软件,必须验证付款信息才能购物是怎么回事???

    答案: 在你这台设备上再设置一下,具体方法是:1.点设置进入2.点iTunes Store 和App Store 3.点 Apple ID ,如果没设置,设置一下,如果有的,再点击 4.出现一上选择的 ...

  9. 本地数据Store。Cookie,Session,Cache的理解。Timer类主要用于定时性、周期性任务 的触发。刷新Store,Panel

    本地数据Store var monthStore = Ext.create('Ext.data.Store', { storeId : 'monthStore', autoLoad : false, ...

随机推荐

  1. 基于PHP+Ajax实现表单验证的详解

    一,利用键盘响应,在不刷新本页面的情况下验证表单输入是否合法 用户通过onkeydown和onkeyup事件来触发响应事件.使用方法和onclick事件类似.onkeydown表示当键盘上的键被按下时 ...

  2. [Tools] 远程登录surface字体过大解决方法

    [背景] 这两天一直远程登录surface,使用surface干活,每次分辨率超大,看着就感觉像显示驱动没装好似的,必须得找个办法来设置 [开工] 在surface上设置低一点的分辨率,成功,但是远程 ...

  3. Java Socket编程(转)

    Java Socket编程 对于Java Socket编程而言,有两个概念,一个是ServerSocket,一个是Socket.服务端和客户端之间通过Socket建立连接,之后它们就可以进行通信了.首 ...

  4. jbox使用总结

    jbox是一个不错的插件 当使用get打开新页面的时候,可以使用h.对像ID来获得对像ID的值 Js代码 js代码: /** * @description: test * @author: BrinP ...

  5. Codeforces VK Cup 2012 Round 3 A. Variable, or There and Back Again(dfs)

    题目链接:http://codeforces.com/problemset/problem/164/A 思路:用vector分别保留原图和发图,然后分别从val值为1的点正向遍历,va值为2的点反向遍 ...

  6. MySQL级联删除的问题

    一.FOREIGN KEY 的定义分为两种:列级约束和表级约束 .列及约束的话,可以在列定义的同时,定义外键约束.比如 如果有2张表,主表:T1(A1 )) 要在从表T2中定义外键列这可以: Crea ...

  7. 【java基础】面向过程~面向对象

    相信大家都知道这两个东西,可是大家是如何知道的呢?我们又该如何区分这个东西到底是面向过程还是面向对象的呢? 那,我们首先就要知道什么是面向过程,什么是面向对象: 面向过程"(Procedur ...

  8. 非旋转Treap及可持久化[Merge,Split]

    http://memphis.is-programmer.com/posts/46317.html http://fanhq666.blog.163.com/blog/static/819434262 ...

  9. DOM系列---基础篇

    DOM系列---基础篇   DOM (Document Object Model) 即文档对象模型, 针对 HTML 和 XML 文档的 API (应用程序接口) .DOM 描绘了一个层次化的节点树, ...

  10. 【Clr in c#】方法

    1. 引用类型(class)与值类型(strust)的构造函数(实例构造器) 1,  创建一个引用类型的实例时,首先为实例的数据字段分配内存,然后初始对象的附加字段,最后调用实例构造器来设置对象的初始 ...