An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We'll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we'll assume the worm makes it out.
【杭电ACM】1.2.2 Climbing Worm
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=2&problemid=4
1 #include <iostream>
2 using namespace std;
3
4 int main(){
5 int n, u, d, count;
6 while(cin >> n >> u >> d){
7 if(n == 0){
8 break;
9 }
10 count = 1;
11 n -= u;
12 while(n > 0){
13 n += d;
14 n -= u;
15 count += 2;
16 }
17 cout << count << endl;
18 }
19
20 return 0;
21 }