94 cigarettes

cigarettes

时间限制: 3000 ms  |  内存限制: 65535 KB 难度: 2
描述

Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them

one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette. 
Now,do you know how many cigarettes can Tom has?

输入
First input is a single line,it's n and stands for there are n testdata.then there are n 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.
样例输入
3
4 3
10 3
100 5
样例输出
5
14
124

这个题的意思是:

输入两个数,第一个表示他现在有多少香烟,第二个数表示多少个烟头呢个换一个香烟,注意烟头不能扔不能借,问每种给出的数据 最多能吸多少烟,当然假设有烟主角就会吸完,汗.....烟鬼..(大家千万别沾染不好的生活习惯啊,这样不好.....)


思路比较简单,直接用循环来全程模拟他吸烟和换烟的全过程,这也是循环的好处,设定好条件,到一定时候,自动终止运行,省去了复杂的计算,让程序自己运行出结果.....

 
#include
int main()
{int t,a,b,x,y,z,s;
scanf("%d",&t);
while(t--)
{scanf("%d%d",&a,&b);z=a;s=z;//s是总共吸烟的数量while(z>=b)//z 表示的是现有的烟头数量,只要可以换香烟,就继续循环{x=z/b;y=z%b;z=x+y;//x是新换到的烟数量,y是每次换烟后,余下的烟头数量s=s+x;//累加吸烟数量.....if(z




本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部