题目:    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. C中的野指针—如何避免

    转自:http://www.cnblogs.com/viviwind/archive/2012/08/14/2638810.html 先看一个例子: struct student{ char* nam ...

  2. 基于能量收集的智能家居-2013国家级大学生创业实践项目申报_商业计划书_V0.2

    SmartHome项目商业计划 基于能量收集的 免电池无线智能家居系统    IA-SmartHome团队    2012.12     l  基于无线的智能家居解决方案,节省施工成本: l  基于能 ...

  3. (C#基础) byte[] 之初始化, 赋值,转换。(转)

    byte[] 之初始化赋值 用for loop 赋值当然是最基本的方法,不过在C#里面还有其他的便捷方法. 1. 创建一个长度为10的byte数组,并且其中每个byte的值为0. byte[] myB ...

  4. ViewPager+tab+Fragment的滑动

    package teamhgl.xinwensudu; import android.os.Bundle;import android.support.v4.app.Fragment;import a ...

  5. Oracle常用命令

    查看数据库锁的情况 SELECT object_name, machine, s.sid, s.serial#  FROM gv$locked_object l, dba_objects o, gv$ ...

  6. css的重置和原子类的使用

    @charset "utf-8";/* Reset Definitions*/body, div, p, a, ul, ol, li, dl, dt, dd, h1, h2, h3 ...

  7. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  8. 余数 2015广工校赛 C 魔幻任务

    题目传送门 题意:问n位最小能整除47的数字 分析:打表发现前面都是100000...,后两位就是100000%47后到47的距离,就是快速幂求1000000%47的值,47-它就是后两位 #incl ...

  9. git 学习笔记5--rm & mv,undo

    rm 删除文件 rm <file> #Unix删除文件 git rm <file> # git删除文件 git rm -f <file> # git强制删除文件 g ...

  10. wordpress修改上传文件大小限制

    在为有的客户搭建 WordPress 网站时,有时会遇到因为所在的服务器限制了上传文件大小而无法上传较大的附件,WordPress的媒体文件上传可以看到,大多数都是2MB或者8MB.如果是图片的话可能 ...