1. 程式人生 > >nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用過的,那一部分是沒有用過的)

nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用過的,那一部分是沒有用過的)

emp code ping using num 內存 integer lin size

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 }

nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用過的,那一部分是沒有用過的)