Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 18097 | Accepted: 7441 |
Description
Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.
How many cigarettes can Peter have?
How many cigarettes can Peter have?
Input
Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.
Output
For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.
Sample Input
4 3 10 3 100 5
Sample Output
5 14 124
Source
问题链接:POJ2509 UVA10346 Peter's Smokes
问题简述:
彼得有n支雪茄,每k个烟头可以换一支新雪茄,问彼得最多可以吸多少支雪茄。
问题分析:
吸雪茄,每k个烟头可以换一支新雪茄,迭代计算问题,是一个模拟过程。
这个题的结果与喝可乐略有不同,不可借烟头。参见参考链接。
题记:(略)
参考链接:UVA11150 Cola【数学+模拟】
/* POJ2509 UVA10346 Peter's Smokes */ #include <iostream> #include <stdio.h> using namespace std; int main() { int n, k, ans; while(~scanf("%d%d", &n, &k)) { ans = 0; while(n >= k) { ans += k * (n / k); n = n % k + n / k; } ans += n; printf("%d\n", ans); } return 0; }