zoukankan      html  css  js  c++  java
  • (HDOJ 1049)Climbing Worm


     Climbing Worm

    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 should 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 1 
    20 3 1 
    0 0 0
     

    Sample Output
    17 
    19
     

    Source
     

     AC code:

     #include<stdio.h>

    int main()
    {
         
    int n,u,d;
         
    int count,i,s;
         
    while(scanf("%d %d %d",&n,&u,&d)&&n)
         {
             
    if(n<=u) s=1;
             
    else
             {
                 
    for(i=1; ; i++)
                 {
                     
    if(n-(u-d)*i<=u)
                     
    break;
                     }
                     count
    =i;
                     s
    =2*count+1;

             }
             printf(
    "%d\n",s);
            }
         
    return 0;
    } 

    作者:cpoint
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    Python 数据驱动 unittest + ddt
    接口知识介绍
    python 爬虫
    python 接口测试(三)
    基于PCA和SVM的人脸识别系统-error修改
    二分查找算法
    JAVA中运用数组的四种排序方法
    [Matlab] Attempt to execute SCRIPT *** as a function
    第36讲 activityForResult
    第35讲 Activity入门和跳转
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015327.html
Copyright © 2011-2022 走看看