D - New Year Candles
2014-02-18 20:55
288 查看
Description
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make bwent
out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input
The single line contains two integers, a and b(1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).
Output
Print a single integer — the number of hours Vasily can light up the room for.
Sample Input
Input
Output
Input
Output
分析:其实这道题认真读不难的,水题。大意是:a根蜡烛,b根烧剩的蜡烛能变成一根新蜡烛,一根烧一小时,问能烧几小时。
下面给参考代码:
#include <stdio.h>
int main()
{
int a, b,sum=0,leave=0;
scanf("%d %d",&a,&b);
while(a)
{
sum+=a;
leave+=a;
a=leave/b;
leave%= b;
}
printf("%d\n", sum);
return 0;
}
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make bwent
out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input
The single line contains two integers, a and b(1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).
Output
Print a single integer — the number of hours Vasily can light up the room for.
Sample Input
Input
4 2
Output
7
Input
6 3
Output
8
分析:其实这道题认真读不难的,水题。大意是:a根蜡烛,b根烧剩的蜡烛能变成一根新蜡烛,一根烧一小时,问能烧几小时。
下面给参考代码:
#include <stdio.h>
int main()
{
int a, b,sum=0,leave=0;
scanf("%d %d",&a,&b);
while(a)
{
sum+=a;
leave+=a;
a=leave/b;
leave%= b;
}
printf("%d\n", sum);
return 0;
}
相关文章推荐
- Problem--379A--Codeforces--A. New Year Candles
- A. New Year Candles----模拟
- Codeforces New Year Candles
- [cf]New Year Candles
- codeforces -- goodbye2013 ---A. New Year Candles
- 379A - New Year Candles
- CodeForces 379 A.New Year Candles(水~)
- CodeForces-379A-New Year Candles
- A. New Year Candles
- new year's resolutions
- Happy New Year!
- ZOJ 2315 New Year Bonus Grant(贪心)
- [CodeForces500B]New Year Permutation[floyd]
- codeforces——500A—— New Year Transportation
- C. New Year Snowmen --优先队列
- codeforces——723A—— The New Year: Meeting Friends
- 【原创】new year resolution
- [ACdream 1212 New Year Bonus Grant]贪心
- 2013年7月21号的题目: New Year Bonus Grant&&Sarov zones
- New Year Bonus Grant(SGU195,贪心or区间DP)