nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用过的,那一部分是没有用过的)...

本文探讨了如何通过算法计算一个人在保留所有烟蒂的情况下,能够制作并抽吸多少支香烟的问题。具体而言,当收集到一定数量的烟蒂(k>1),可以将这些烟蒂重新制成一支新的香烟。文章提供了输入输出样例和C/C++代码实现,展示了如何计算最多可以得到的香烟数目。

94-cigarettes


内存限制:64MB 时间限制:3000ms 特判: No
通过数:13 提交数:20 难度: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

C/C++ AC
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <stack>
 7 #include <set>
 8 #include <map>
 9 #include <queue>
10 #include <climits>
11 
12 using namespace std;
13 const int MAX = 1e6 + 10;
14 int n, a, b;
15 
16 int main()
17 {
18     cin >>n;
19     while (n --)
20     {
21         int ans = 0, temp;
22         scanf("%d%d", &a, &b);
23 
24         while (a >= b)
25         {
26             temp = a / b;
27             ans += temp * b; // temp * b 表示已经用过的
28             a = temp + a % b;
29         }
30         ans += a;
31         printf("%d\n", ans);
32     }
33 }

 

转载于:https://www.cnblogs.com/GetcharZp/p/9320622.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值