题目:    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. Web开发基本准则-55实录-Web访问安全

    Web开发工程师请阅读下面的前端开发准则,这是第一部分,强调了过去几年里我们注意到的Web工程师务须处理的Web访问安全基础点.尤其是一些从传统软件开发转入互联网开发的工程师,请仔细阅读,不要因为忽视 ...

  2. OpenMesh 之向量操作

    OpenMesh 提供了许多可供使用的向量操作函数,使用特别方便. 计算距离: 从官方文档可以看到OpenMesh提供了5个函数,分别为 Scalar length() const        // ...

  3. Fragment 操作原理

      fragment 本质 fragment 本质上是 view 的容器和控制器,fragment 是 activity 的碎片. activity 是什么呢?activity 是四大组件之一,因为 ...

  4. (转载)如何借助KeePassX在Linux上管理多个密码

    转自:http://netsecurity.51cto.com/art/201311/417764.htm 如今,基于密码的身份验证在网上非常普遍,结果你恐怕数不清自己到底在使用多少个密码.实际上,据 ...

  5. BurpSuite的使用总结

    BurpSuite BurpSuite 是一款使用Java编写的,用于Web安全审计与扫描套件.它集成了诸多实用的小工具以完成http请求的转发/修改/扫描等,同时这些小工具之间还可以 互相协作,在B ...

  6. hdu 3037 Saving Beans Lucas定理

    Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. python中的变量和数据类型

    一.变量定义:变量是计算机内存中的一块区域,存储规定范围内的值,值 可以改变,通俗的说变量就是给数据起个名字. 二.变量命名规则: 1. 变量名由字母.数字.下划线组成 2. 数字不能开头 3. 不可 ...

  8. BZOJ 1189 [HNOI2007]紧急疏散evacuate

    Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是一 ...

  9. CSS background 属性

    CSS 参考手册 实例 如何在一个声明中设置所有背景属性: body { background: #00FF00 url(bgimage.gif) no-repeat fixed top; } 亲自试 ...

  10. CodeForces#275--DIV 2--A

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...