Climbing WormTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 14196 Accepted Submission (s): 9560
Problem Descriptionan inch worm is at the bottom of a well n inches deep. It has enough-climb u inches every minute, but then have 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 is 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.
Inputthere'll be multiple problem instances. Each line would contain 3 positive integers n, u and D. These give the values mentioned in the paragraph above. Furthermore, assume D < u and N < 100. A value of n = 0 indicates end of output.
Outputeach input instance should generate a single integer on a line, indicating the number of minutes it takes for the Wo RM to climb off of the well.
Sample Input
10 2 120 3 10 0 0
Sample Output
1719
Sourceeast Central North America 2002
Recommendwe carefully selected several similar problems for you:1021 1019 1108 1071 1009
There is nothing to explain, the topic is very clear, talking about a small bug to climb the water well story! (I also have to climb the water well as soon as possible ...) )
#include <iostream> #include <cstdio>using namespace Std;int main () { int n,u,d; while (scanf ("%d%d%d", &n,&u,&d)!=eof) { if (n==0) break ; int s=0,t=0; while (S<n) { s+=u; t++; if (s>=n) {break ; } S-=d; t++; } printf ("%d\n", t); } return 0;}
Hdu-1049-climbing Worm (c + + && programming Beginner's question ...)