http://poj.org/problem?id=2509

Peter's smokes
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16957   Accepted: 6984

Description

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. 
How many cigarettes can Peter have? 

Input

Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.

Output

For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.

Sample Input

4 3
10 3
100 5

Sample Output

5
14
124

Source

 
 
分析:
这道题没有可以“先借后还”的要求,所以要最后判断结果即可。
 
 
AC代码:
 #include<stdio.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
int sum = a;
while(a >= b)
{
sum += a/b;
a = a/b + a%b;
}
printf("%d\n",sum);
}
return ;
}

poj 2509 Peter's smokes的更多相关文章

  1. POJ 2509 Peter's smokes(Peter的香烟)

    POJ 2509 Peter的香烟 描述 Peter抽烟.他抽烟一个个地抽着烟头.从 k (k>1) 个烟头中,他可以抽一根新烟.彼得可以抽几支烟? 输入 输入是一系列行.每行包含两个给出n和k ...

  2. Peter's smokes -poj 2509

    题意:彼得有n支雪茄,每k个烟头可以换一支新雪茄,问彼得最多可以吸多少支雪茄 ? 当时自己做时,错在了直接在while循环开始前,便将雪茄的初始数量给加上了,然而应该是先处理后再加上最终剩余的雪茄数量 ...

  3. UVa 10346 - Peter's Smokes

    题目大意:Peter有n支烟,每k个剩下的烟头可以卷成一支新烟,问Peter能吸多少跟烟? 简单数学题. #include <cstdio> int main() { #ifdef LOC ...

  4. POJ 2509

    #include <iostream> #include <stdio.h> using namespace std; int main() { //freopen(" ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. POJ解题经验交流

    感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理.   题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...

  7. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

  8. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  9. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

随机推荐

  1. 浅析C++的内存管理

    在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/ 静态存储区和常量存储区. 栈,就是那些由编译器在需要的时候分配,在不需要的时候自动清楚的变量的存储区.里面的变量通常是局部变量.函数参 ...

  2. jfinal框架教程-学习笔记(二)

    上一节介绍了jfinal框架的简单搭建,这节通过一个小例子了解jfinal的结构和特点 先上图 1.建数据库(我用的是oracle数据库,其他的相对也差不多) -- Create table crea ...

  3. HDFS的联盟Federation

    一:概述 1.单个namenode的局限性 namespace的限制 单个namenode所能存储的对象受到JVM中的heap size的限制 namenode的扩张性 不可以水平扩张 隔离性 单个n ...

  4. 单个未知大小图片在div里面垂直居中的方法。。。添加辅助元素挤一下位置达到居中

    单个未知大小图片在div里面垂直居中的方法...添加辅助元素挤一下位置达到居中   <div class="ServicesLiTopPic"> <i>&l ...

  5. 在magento中如何回复客户的评论

    magento — 在magento中如何回复客户的评论 发表于 2012 年 8 月 18 日 agento本身是不带 回复评论的功能的,现成的扩展(无论免费的还是商业的)也没找到,那就自己写一个吧 ...

  6. jquery 分页

    最近有点无所事事,无聊之极! 啊啊啊,表示很痛苦! <div id="tablist_01" class="list_tab"> <table ...

  7. [LeetCode]题解(python):033-Search in Rotated Sorted Array

    题目来源 https://leetcode.com/problems/search-in-rotated-sorted-array/ Suppose a sorted array is rotated ...

  8. PySe-003-Se-WebDriver 启动浏览器之一 - Firefox

    此文主要演示 MacOX 下 WebDriver 启动 Firefox 浏览器,因 WebDriver 对 Firefox 浏览器是原生支持的,因而无需像启动其他浏览器一样需要相对应的 driver. ...

  9. 编译mod_jk.so

    编译mod_jk.so前,需要先到http://tomcat.apache.org/download-connectors.cgi去下载tomcat-connectors-1.2.41-src.tar ...

  10. LeetCode Shortest Word Distance II

    原题链接在这里:https://leetcode.com/problems/shortest-word-distance-ii/ 题目: This is a follow up of Shortest ...