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. Delphi 200X、XE中如何用并行实现循环的计算

    interface uses Classes, SysUtils; type TParallelProc = reference to procedure(i: Integer; ThreadID: ...

  2. 如何在html中插入视频

    如何在html中插入视频 1,插入优酷视频: 在优酷分享界面有个html代码,直接复制放入body中,定义div的align居中即可 2.插入本地视频:用video属性  用mp4格式 <vid ...

  3. Android 学习

    入门: Android疯狂讲义 http://hukai.me/android-training-course-in-chinese/index.html http://segmentfault.co ...

  4. nginx博客系统(内含nginx图片缩略图处理代码,不错)

    一直以来都在Qzone.CSDN等上面写博客,偶尔有些想法就在Paas平台上搭建服务,新浪和曾经的google上都用过其appengine.可是在别人的平台上写东西,总归有些不方便,有受制于人的感觉. ...

  5. SQL Server数据库连接字符串的组成

    DB驱动程序常见的驱动程序如下: ODBC   ODBC(Open Database Connectivity,开放数据库互连)是微软公司开放服务结构(WOSA,Windows Open Servic ...

  6. mysql存储过程之游标遍历数据表

    原文:mysql存储过程之游标遍历数据表 今天写一个mysql存储过程,根据自己的需求要遍历一个数据表,因为对存储过程用的不多,语法不甚熟悉,加之存储过程没有调试环境,花了不少时间才慢慢弄好,故留个痕 ...

  7. asp.net字符串的数学表达式计算结果

    using System; using System.Collections.Generic; using System.Web; using System.CodeDom.Compiler; usi ...

  8. LightOj1074 - Extended Traffic(SPFA最短路)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1074 题意:有n个城市,每个城市有一个拥堵值a[i],m条单向路u到v,从u到v所需时 ...

  9. qt 屏幕旋转

    qt屏幕旋转的方法 参考链接 http://mikenoodle.blog.163.com/blog/static/11333522010102754154616/ http://blog.csdn. ...

  10. C#中override和overload的区别

    重载应该叫overload,重写叫override:重载某个方法是在同一个类中发生的!重写是在子类中重写父类中的方法. 1.override:   父类:public virtual string T ...