Hdu-1049-climbing Worm (c + + && programming Beginner's question ...)

Source: Internet
Author: User

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 ...)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.