您的位置:首页 > 其它

94 cigarettes

2015-07-11 11:48 253 查看


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<stdio.h>
int main()
{int t,a,b,x,y,z,s;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
z=a;s=z;<span style="font-family: Arial, Helvetica, sans-serif;">//s是总共吸烟的数量</span>

while(z>=b)//z 表示的是现有的烟头数量,只要可以换香烟,就继续循环
{
x=z/b;y=z%b;z=x+y;//x是新换到的烟数量,y是每次换烟后,余下的烟头数量
s=s+x;//累加吸烟数量.....
if(z<b)
printf("%d\n",s);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: