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. 【微信开发之问题集锦】redirect_uri 参数错误

    问题答案:看看网页授权域名是不是以"http://",是则去掉.(如果网页授权域名都没修改,那就去修改吧,要注意域名不要带"http://"."htt ...

  2. 将真彩色转换成增强色的方法(即RGB32位或RGB24位颜色转换成RGB16位颜色的函数)

    今天由于程序需要,需要将真彩色转换成增强色进行颜色匹配,上网搜了一下没搜到相应函数,于是研究了一下RGB16位的增强色,写了这个函数: public static int RGB16(int argb ...

  3. C++线程池的实现(二)

    参考文章:http://blog.csdn.net/huyiyang2010/archive/2010/08/10/5801597.aspx // CThread.h #ifndef __MY_THR ...

  4. Linux CentOS 编绎安装Python 3.5

    Linux CentOS 编绎安装Python 3.5 先决条件(若无安装,则不能编绎使用idle3):yum install tk-devel xz -d Python-3.5.0.tar.xzta ...

  5. 文件操作_菜单<代码>

    info文件中的内容为: { "河北省": {"石家庄": {"无极县":"", "高邑县":&qu ...

  6. i++和++i的区别

    先看如下程序: class Program { static void Main(string[] args) { ; ; ; ; x = i++; Console.WriteLine("x ...

  7. iostart命令

    Linux系统中的 iostat命令可以对系统的磁盘IO和CPU使用情况进行监控.iostat属于sysstat软件包,可以用yum -y install sysstat 直接安装. 1.基本使用:i ...

  8. 常用jq选择器和遍历的使用

    1.jq的选择器,常用有哪些? class id > ~ ul li a 2.遍历的使用(在使用用遍历节点时,我们的注意遍历在不传递参数(也就是传参),代表的是传递局部全局,也就是"* ...

  9. 选择年份 php的写法要比js简洁一些

    所以遇到下拉框默认选择的情况,用php写比较方便一些 <select type="text" class="form-control_2" name=&q ...

  10. SQL把表中的数据复制到另一个数据库中

    1 删除整张表的数据,并还原自增长值TRUNCATE TABLE TbWeixinActivity 2 3张表左连接select a.ID,c.Name,b.nickname,a.CreateDate ...