nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用过的,那一部分是没有用过的)
Posted getcharzp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用过的,那一部分是没有用过的)相关的知识,希望对你有一定的参考价值。
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 ", ans); 32 } 33 }
以上是关于nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用过的,那一部分是没有用过的)的主要内容,如果未能解决你的问题,请参考以下文章
你能分清楚 Authentication 和 Authorization 吗?