博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-2509(Water,Greedy)
阅读量:6738 次
发布时间:2019-06-25

本文共 735 字,大约阅读时间需要 2 分钟。

2509:Peter's smokes

时间限制:

1000ms

内存限制:

65536kB

描述

Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1(事实上吸过的烟超过>=k即可) butts he can roll a new cigarette.

How many cigarettes can Peter have?

输入

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

输出

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

样例输入

4 3

10 3

100 5

样例输出

5

14

124

 

#include"iostream"

using namespace std;
int main()
{
 int n,k;
 int ans;
 while(cin>>n>>k)
 {
  ans=n;//初始化ans
  while(n>=k)
  {
   ans+=n/k;//更新ans
   n=n/k+n%k;//更新n
  }
  cout<<ans<<endl;
 }
}

转载于:https://www.cnblogs.com/lzhitian/archive/2011/08/16/2140070.html

你可能感兴趣的文章
Perl获取机器hostname,ip(跨平台)
查看>>
iptables的基本语法格式
查看>>
Http协议和IO模型
查看>>
【数据结构】将一组数据升序排序(利用堆排序)
查看>>
linux中用户,组管理
查看>>
用什么开发软件
查看>>
makefile(07)_路径搜索
查看>>
数据结构(06)_栈
查看>>
openstack
查看>>
聊聊flink JobManager的High Availability
查看>>
聊聊Elasticsearch的SingleObjectCache
查看>>
运维CMDB系统
查看>>
面向对象基本概念
查看>>
计算机网络(一)——互联网层
查看>>
hive关联查询连接hbase的外部表时,内存溢出问题
查看>>
顺序结构的程序设计-考点
查看>>
Web前端面试指导(十四):如何居中一个元素(正常、绝对定位、浮动元素)?
查看>>
php基础
查看>>
磁盘提示使用驱动器中的光盘之前需要格式化资料怎样找回
查看>>
C++后台开发岗)
查看>>