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;
}
相关文章推荐
- LeetCode 1 Two Sum 排序后快速求解
- POJ-1007
- c++启动外部exe程序,出现闪退或缺少东西之类的问题,而双击exe没问题的情况
- 自动编译工具
- CodeIgniter学习笔记(十四)——CI中的文件上传
- 那些年不可错过的xcode插件
- linux下安装boost
- java 学习笔记
- 由malloc内存分配是否连续 引出的 一些概念
- JAVA基础之面向对象(个人学习笔记,更新修改中)
- iOSpush过后返回多级界面
- UI4_LabelChess
- Android视图绘制流程完全解析
- 为什么和不优质的女人打交道意味着压抑和斗争
- OC中NS开头的来源
- nimbus
- C# Excel导出
- [NOI 2014复习]斜率优化(BZOJ 1096、BZOJ 1010)
- 小贝_mysql 存储引擎及事务概念
- hashcode equals