HDU 1049 climbing Worm

Source: Internet
Author: User
Climbing Worm Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/others) total submission (s): 12245 accepted submission (s): 8254

Problem description 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.
 
Input There will be multiple problem instances. each line will contain 3 positive integers n, U and D. these give the values mentioned in the paragraph above. furthermore, you may assume d <u and n <100. A value of N = 0 indicates end of output.
 
Output Each input instance shoshould generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well.
 
Sample Input
10 2 120 3 10 0 0
 
Sample output
1719
 
Simulation:
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;int main (){    int k,n,m;    while(cin>>k>>n>>m)    {        if(k==0&&n==0&&m==0) break;        int sum=0;        int t=0;        while(sum<k)        {          sum+=n;          t++;          if(sum>=k)            break;          sum-=m;          t++;        }           cout<<t<<endl;    }    return 0;}


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.